Skip to content

Commit 4690531

Browse files
Mcdb 80886 fix httpx timeout (#97)
* Fix timeout extraction from factory methods. * Introduce new factory methods for testing purposes. * Remove testing code.
1 parent 7cfac10 commit 4690531

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

singlestoredb/ai/chat.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,27 @@ def SingleStoreChatFactory(
9090
'signature_version': UNSIGNED,
9191
'retries': {'max_attempts': 1, 'mode': 'standard'},
9292
}
93-
if http_client is not None and http_client.timeout is not None:
94-
cfg_kwargs['read_timeout'] = http_client.timeout
95-
cfg_kwargs['connect_timeout'] = http_client.timeout
93+
# Extract timeouts from http_client if provided
94+
t = http_client.timeout if http_client is not None else None
95+
connect_timeout = None
96+
read_timeout = None
97+
if t is not None:
98+
if isinstance(t, httpx.Timeout):
99+
if t.connect is not None:
100+
connect_timeout = float(t.connect)
101+
if t.read is not None:
102+
read_timeout = float(t.read)
103+
if connect_timeout is None and read_timeout is not None:
104+
connect_timeout = read_timeout
105+
if read_timeout is None and connect_timeout is not None:
106+
read_timeout = connect_timeout
107+
elif isinstance(t, (int, float)):
108+
connect_timeout = float(t)
109+
read_timeout = float(t)
110+
if read_timeout is not None:
111+
cfg_kwargs['read_timeout'] = read_timeout
112+
if connect_timeout is not None:
113+
cfg_kwargs['connect_timeout'] = connect_timeout
96114

97115
cfg = Config(**cfg_kwargs)
98116
client = boto3.client(

singlestoredb/ai/embeddings.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,27 @@ def SingleStoreEmbeddingsFactory(
6666
'signature_version': UNSIGNED,
6767
'retries': {'max_attempts': 1, 'mode': 'standard'},
6868
}
69-
if http_client is not None and http_client.timeout is not None:
70-
cfg_kwargs['read_timeout'] = http_client.timeout
71-
cfg_kwargs['connect_timeout'] = http_client.timeout
69+
# Extract timeouts from http_client if provided
70+
t = http_client.timeout if http_client is not None else None
71+
connect_timeout = None
72+
read_timeout = None
73+
if t is not None:
74+
if isinstance(t, httpx.Timeout):
75+
if t.connect is not None:
76+
connect_timeout = float(t.connect)
77+
if t.read is not None:
78+
read_timeout = float(t.read)
79+
if connect_timeout is None and read_timeout is not None:
80+
connect_timeout = read_timeout
81+
if read_timeout is None and connect_timeout is not None:
82+
read_timeout = connect_timeout
83+
elif isinstance(t, (int, float)):
84+
connect_timeout = float(t)
85+
read_timeout = float(t)
86+
if read_timeout is not None:
87+
cfg_kwargs['read_timeout'] = read_timeout
88+
if connect_timeout is not None:
89+
cfg_kwargs['connect_timeout'] = connect_timeout
7290

7391
cfg = Config(**cfg_kwargs)
7492
client = boto3.client(

0 commit comments

Comments
 (0)