@@ -49,6 +49,7 @@ def __init__(
4949 temperature : float = 0.1 ,
5050 top_p : float = 0.9 ,
5151 max_tokens : int = 2000 ,
52+ timeout : Optional [float ] = None ,
5253 ):
5354 """
5455 Initialize Qwen VL API client
@@ -59,6 +60,8 @@ def __init__(
5960 temperature: Sampling temperature
6061 top_p: Nucleus sampling
6162 max_tokens: Maximum tokens to generate
63+ timeout: Request timeout in seconds (defaults to the DashScope
64+ SDK's own default of 300s when not set)
6265 """
6366 super ().__init__ (model = model , stream = False )
6467
@@ -72,6 +75,7 @@ def __init__(
7275 self .temperature = temperature
7376 self .top_p = top_p
7477 self .max_tokens = max_tokens
78+ self .timeout = timeout
7579
7680 # Cost tracking
7781 self ._total_requests = 0
@@ -151,15 +155,22 @@ def generate(
151155 messages = self ._format_messages (content , system_prompt )
152156
153157 # Call API
158+ call_kwargs : Dict [str , Any ] = {
159+ "api_key" : self .api_key ,
160+ "model" : self .model ,
161+ "messages" : messages ,
162+ "temperature" : self .temperature ,
163+ "top_p" : self .top_p ,
164+ "max_length" : self .max_tokens ,
165+ }
166+ if self .timeout is not None :
167+ # DashScope reads the socket timeout from `request_timeout`;
168+ # a `timeout=` kwarg is accepted but dropped into the request
169+ # body unused, so this is not a naming choice.
170+ call_kwargs ["request_timeout" ] = self .timeout
171+
154172 try :
155- response = MultiModalConversation .call (
156- api_key = self .api_key ,
157- model = self .model ,
158- messages = messages ,
159- temperature = self .temperature ,
160- top_p = self .top_p ,
161- max_length = self .max_tokens ,
162- )
173+ response = MultiModalConversation .call (** call_kwargs )
163174
164175 self ._total_requests += 1
165176
0 commit comments