@@ -82,29 +82,30 @@ def obo_token_getter() -> Optional[str]:
8282 if hosting_platform is not None :
8383 info .hosting_platform = hosting_platform
8484
85+ # Extract timeouts from http_client if provided
86+ t = http_client .timeout if http_client is not None else None
87+ connect_timeout = None
88+ read_timeout = None
89+ if t is not None :
90+ if isinstance (t , httpx .Timeout ):
91+ if t .connect is not None :
92+ connect_timeout = float (t .connect )
93+ if t .read is not None :
94+ read_timeout = float (t .read )
95+ if connect_timeout is None and read_timeout is not None :
96+ connect_timeout = read_timeout
97+ if read_timeout is None and connect_timeout is not None :
98+ read_timeout = connect_timeout
99+ elif isinstance (t , (int , float )):
100+ connect_timeout = float (t )
101+ read_timeout = float (t )
102+
85103 if info .hosting_platform == 'Amazon' :
86104 # Instantiate Bedrock client
87105 cfg_kwargs = {
88106 'signature_version' : UNSIGNED ,
89107 'retries' : {'max_attempts' : 1 , 'mode' : 'standard' },
90108 }
91- # Extract timeouts from http_client if provided
92- t = http_client .timeout if http_client is not None else None
93- connect_timeout = None
94- read_timeout = None
95- if t is not None :
96- if isinstance (t , httpx .Timeout ):
97- if t .connect is not None :
98- connect_timeout = float (t .connect )
99- if t .read is not None :
100- read_timeout = float (t .read )
101- if connect_timeout is None and read_timeout is not None :
102- connect_timeout = read_timeout
103- if read_timeout is None and connect_timeout is not None :
104- read_timeout = connect_timeout
105- elif isinstance (t , (int , float )):
106- connect_timeout = float (t )
107- read_timeout = float (t )
108109 if read_timeout is not None :
109110 cfg_kwargs ['read_timeout' ] = read_timeout
110111 if connect_timeout is not None :
@@ -176,8 +177,18 @@ def auth_flow(
176177 request .headers ['X-S2-OBO' ] = obo_val
177178 yield request
178179
180+ # Build timeout configuration
181+ if connect_timeout is not None and read_timeout is not None :
182+ t = httpx .Timeout (connect = connect_timeout , read = read_timeout )
183+ elif connect_timeout is not None :
184+ t = httpx .Timeout (connect = connect_timeout )
185+ elif read_timeout is not None :
186+ t = httpx .Timeout (read = read_timeout )
187+ else :
188+ t = 60.0 # default OpenAI client timeout
189+
179190 http_client = httpx .Client (
180- timeout = 30 ,
191+ timeout = t ,
181192 auth = OpenAIAuth (),
182193 )
183194
@@ -188,8 +199,7 @@ def auth_flow(
188199 model = model_name ,
189200 streaming = streaming ,
190201 )
191- if http_client is not None :
192- openai_kwargs ['http_client' ] = http_client
202+ openai_kwargs ['http_client' ] = http_client
193203 return ChatOpenAI (
194204 ** openai_kwargs ,
195205 ** kwargs ,
0 commit comments