11import warnings
22from typing import Any , Dict , Optional
33
4- from pydantic import BaseModel , ConfigDict , Field , field_validator
4+ from pydantic import ConfigDict , Field , field_validator
55
66from .base import BaseAvatar
77
1010AKOOL_SAMPLE_RATE = 16000
1111
1212
13- class LiveAvatarAvatarOptions ( BaseModel ):
13+ class LiveAvatarAvatar ( BaseAvatar ):
1414 model_config = ConfigDict (extra = "forbid" )
1515
1616 api_key : str = Field (..., description = "LiveAvatar API key" )
@@ -31,110 +31,117 @@ def validate_quality(cls, v: str) -> str:
3131 raise ValueError (f"Invalid quality '{ v } '. Must be one of: { ', ' .join (valid )} " )
3232 return v
3333
34-
35- class LiveAvatarAvatar (BaseAvatar ):
36- def __init__ (self , ** kwargs : Any ):
37- self .options = LiveAvatarAvatarOptions (** kwargs )
38-
3934 @property
4035 def required_sample_rate (self ) -> int :
4136 return LIVEAVATAR_SAMPLE_RATE
4237
4338 def to_config (self ) -> Dict [str , Any ]:
4439 params : Dict [str , Any ] = {
45- "api_key" : self .options . api_key ,
46- "quality" : self .options . quality ,
47- "agora_uid" : self .options . agora_uid ,
40+ "api_key" : self .api_key ,
41+ "quality" : self .quality ,
42+ "agora_uid" : self .agora_uid ,
4843 }
4944
50- if self .options . agora_token is not None :
51- params ["agora_token" ] = self .options . agora_token
52- if self .options . avatar_id is not None :
53- params ["avatar_id" ] = self .options . avatar_id
54- if self .options . disable_idle_timeout is not None :
55- params ["disable_idle_timeout" ] = self .options . disable_idle_timeout
56- if self .options . activity_idle_timeout is not None :
57- params ["activity_idle_timeout" ] = self .options . activity_idle_timeout
58- if self .options . additional_params is not None :
59- params = {** self .options . additional_params , ** params }
60-
61- enable = self .options . enable if self . options .enable is not None else True
45+ if self .agora_token is not None :
46+ params ["agora_token" ] = self .agora_token
47+ if self .avatar_id is not None :
48+ params ["avatar_id" ] = self .avatar_id
49+ if self .disable_idle_timeout is not None :
50+ params ["disable_idle_timeout" ] = self .disable_idle_timeout
51+ if self .activity_idle_timeout is not None :
52+ params ["activity_idle_timeout" ] = self .activity_idle_timeout
53+ if self .additional_params is not None :
54+ params = {** self .additional_params , ** params }
55+
56+ enable = self .enable if self .enable is not None else True
6257 return {"enable" : enable , "vendor" : "liveavatar" , "params" : params }
6358
6459
65- class HeyGenAvatarOptions (LiveAvatarAvatarOptions ):
66- """Deprecated: use :class:`LiveAvatarAvatarOptions` instead."""
67-
68-
6960class HeyGenAvatar (BaseAvatar ):
7061 """Deprecated: HeyGen has been renamed to LiveAvatar. Use LiveAvatarAvatar instead."""
7162
72- def __init__ (self , ** kwargs : Any ):
63+ model_config = ConfigDict (extra = "forbid" )
64+
65+ api_key : str = Field (..., description = "LiveAvatar API key" )
66+ quality : str = Field (..., description = "Avatar quality: low, medium, or high" )
67+ agora_uid : str = Field (..., description = "Agora UID for the avatar stream" )
68+ agora_token : Optional [str ] = Field (default = None , description = "RTC token for avatar authentication" )
69+ avatar_id : Optional [str ] = Field (default = None , description = "Avatar ID" )
70+ enable : Optional [bool ] = Field (default = None , description = "Enable avatar (default: true)" )
71+ disable_idle_timeout : Optional [bool ] = Field (default = None , description = "Whether to disable idle timeout" )
72+ activity_idle_timeout : Optional [int ] = Field (default = None , description = "Idle timeout in seconds" )
73+ additional_params : Optional [Dict [str , Any ]] = Field (default = None , description = "Additional vendor-specific parameters" )
74+
75+ @field_validator ("quality" )
76+ @classmethod
77+ def validate_quality (cls , v : str ) -> str :
78+ valid = ("low" , "medium" , "high" )
79+ if v not in valid :
80+ raise ValueError (f"Invalid quality '{ v } '. Must be one of: { ', ' .join (valid )} " )
81+ return v
82+
83+ def model_post_init (self , __context : Any ) -> None :
84+ # stacklevel=3: warn() <- model_post_init <- pydantic __init__ <- user code,
85+ # so the warning points at the user's construction site, not pydantic internals.
7386 warnings .warn (
7487 "HeyGenAvatar is deprecated; use LiveAvatarAvatar instead." ,
7588 DeprecationWarning ,
76- stacklevel = 2 ,
89+ stacklevel = 3 ,
7790 )
78- self .options = HeyGenAvatarOptions (** kwargs )
7991
8092 @property
8193 def required_sample_rate (self ) -> int :
8294 return HEYGEN_SAMPLE_RATE
8395
8496 def to_config (self ) -> Dict [str , Any ]:
8597 params : Dict [str , Any ] = {
86- "api_key" : self .options . api_key ,
87- "quality" : self .options . quality ,
88- "agora_uid" : self .options . agora_uid ,
98+ "api_key" : self .api_key ,
99+ "quality" : self .quality ,
100+ "agora_uid" : self .agora_uid ,
89101 }
90102
91- if self .options . agora_token is not None :
92- params ["agora_token" ] = self .options . agora_token
93- if self .options . avatar_id is not None :
94- params ["avatar_id" ] = self .options . avatar_id
95- if self .options . disable_idle_timeout is not None :
96- params ["disable_idle_timeout" ] = self .options . disable_idle_timeout
97- if self .options . activity_idle_timeout is not None :
98- params ["activity_idle_timeout" ] = self .options . activity_idle_timeout
99- if self .options . additional_params is not None :
100- params = {** self .options . additional_params , ** params }
101-
102- enable = self .options . enable if self . options .enable is not None else True
103+ if self .agora_token is not None :
104+ params ["agora_token" ] = self .agora_token
105+ if self .avatar_id is not None :
106+ params ["avatar_id" ] = self .avatar_id
107+ if self .disable_idle_timeout is not None :
108+ params ["disable_idle_timeout" ] = self .disable_idle_timeout
109+ if self .activity_idle_timeout is not None :
110+ params ["activity_idle_timeout" ] = self .activity_idle_timeout
111+ if self .additional_params is not None :
112+ params = {** self .additional_params , ** params }
113+
114+ enable = self .enable if self .enable is not None else True
103115 return {"enable" : enable , "vendor" : "heygen" , "params" : params }
104116
105117
106- class AkoolAvatarOptions ( BaseModel ):
118+ class AkoolAvatar ( BaseAvatar ):
107119 model_config = ConfigDict (extra = "forbid" )
108120
109121 api_key : str = Field (..., description = "Akool API key" )
110122 avatar_id : Optional [str ] = Field (default = None , description = "Avatar ID" )
111123 enable : Optional [bool ] = Field (default = None , description = "Enable avatar (default: true)" )
112124 additional_params : Optional [Dict [str , Any ]] = Field (default = None , description = "Additional vendor-specific parameters" )
113125
114-
115- class AkoolAvatar (BaseAvatar ):
116- def __init__ (self , ** kwargs : Any ):
117- self .options = AkoolAvatarOptions (** kwargs )
118-
119126 @property
120127 def required_sample_rate (self ) -> int :
121128 return AKOOL_SAMPLE_RATE
122129
123130 def to_config (self ) -> Dict [str , Any ]:
124131 params : Dict [str , Any ] = {
125- "api_key" : self .options . api_key ,
132+ "api_key" : self .api_key ,
126133 }
127134
128- if self .options . avatar_id is not None :
129- params ["avatar_id" ] = self .options . avatar_id
130- if self .options . additional_params is not None :
131- params = {** self .options . additional_params , ** params }
135+ if self .avatar_id is not None :
136+ params ["avatar_id" ] = self .avatar_id
137+ if self .additional_params is not None :
138+ params = {** self .additional_params , ** params }
132139
133- enable = self .options . enable if self . options .enable is not None else True
140+ enable = self .enable if self .enable is not None else True
134141 return {"enable" : enable , "vendor" : "akool" , "params" : params }
135142
136143
137- class GenericAvatarOptions ( BaseModel ):
144+ class GenericAvatar ( BaseAvatar ):
138145 model_config = ConfigDict (extra = "forbid" )
139146
140147 api_key : str = Field (..., description = "Generic avatar provider API key" )
@@ -147,61 +154,51 @@ class GenericAvatarOptions(BaseModel):
147154 enable : Optional [bool ] = Field (default = None , description = "Enable avatar (default: true)" )
148155 additional_params : Optional [Dict [str , Any ]] = Field (default = None , description = "Additional vendor-specific parameters" )
149156
150-
151- class GenericAvatar (BaseAvatar ):
152- def __init__ (self , ** kwargs : Any ):
153- self .options = GenericAvatarOptions (** kwargs )
154-
155157 @property
156158 def required_sample_rate (self ) -> int :
157159 return 0
158160
159161 def to_config (self ) -> Dict [str , Any ]:
160162 params : Dict [str , Any ] = {
161- "api_key" : self .options . api_key ,
162- "api_base_url" : self .options . api_base_url ,
163- "avatar_id" : self .options . avatar_id ,
164- "agora_uid" : self .options . agora_uid ,
163+ "api_key" : self .api_key ,
164+ "api_base_url" : self .api_base_url ,
165+ "avatar_id" : self .avatar_id ,
166+ "agora_uid" : self .agora_uid ,
165167 }
166168
167- if self .options . agora_appid is not None :
168- params ["agora_appid" ] = self .options . agora_appid
169- if self .options . agora_token is not None :
170- params ["agora_token" ] = self .options . agora_token
171- if self .options . agora_channel is not None :
172- params ["agora_channel" ] = self .options . agora_channel
173- if self .options . additional_params is not None :
174- params = {** self .options . additional_params , ** params }
169+ if self .agora_appid is not None :
170+ params ["agora_appid" ] = self .agora_appid
171+ if self .agora_token is not None :
172+ params ["agora_token" ] = self .agora_token
173+ if self .agora_channel is not None :
174+ params ["agora_channel" ] = self .agora_channel
175+ if self .additional_params is not None :
176+ params = {** self .additional_params , ** params }
175177
176- enable = self .options . enable if self . options .enable is not None else True
178+ enable = self .enable if self .enable is not None else True
177179 return {"enable" : enable , "vendor" : "generic" , "params" : params }
178180
179181
180- class AnamAvatarOptions ( BaseModel ):
182+ class AnamAvatar ( BaseAvatar ):
181183 model_config = ConfigDict (extra = "forbid" )
182184
183185 api_key : str = Field (..., description = "Anam API key" )
184186 avatar_id : str = Field (..., description = "Anam avatar ID" )
185187 enable : Optional [bool ] = Field (default = None , description = "Enable avatar (default: true)" )
186188 additional_params : Optional [Dict [str , Any ]] = Field (default = None , description = "Additional vendor-specific parameters" )
187189
188-
189- class AnamAvatar (BaseAvatar ):
190- def __init__ (self , ** kwargs : Any ):
191- self .options = AnamAvatarOptions (** kwargs )
192-
193190 @property
194191 def required_sample_rate (self ) -> int :
195192 return 0
196193
197194 def to_config (self ) -> Dict [str , Any ]:
198195 params : Dict [str , Any ] = {
199- "api_key" : self .options . api_key ,
200- "avatar_id" : self .options . avatar_id ,
196+ "api_key" : self .api_key ,
197+ "avatar_id" : self .avatar_id ,
201198 }
202199
203- if self .options . additional_params is not None :
204- params = {** self .options . additional_params , ** params }
200+ if self .additional_params is not None :
201+ params = {** self .additional_params , ** params }
205202
206- enable = self .options . enable if self . options .enable is not None else True
203+ enable = self .enable if self .enable is not None else True
207204 return {"enable" : enable , "vendor" : "anam" , "params" : params }
0 commit comments