Skip to content

Commit 1e74c18

Browse files
Remove 'timeout', go to the previous way of initializing the OpenAI clients; 'http_client' should be configured outside of the factory method.
1 parent 1a71731 commit 1e74c18

File tree

5 files changed

+5
-258
lines changed

5 files changed

+5
-258
lines changed

singlestoredb/ai/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
from .chat import SingleStoreChatFactory # noqa: F401
2-
from .debugv3 import SingleStoreChatFactoryDebugV3 # noqa: F401
32
from .embeddings import SingleStoreEmbeddingsFactory # noqa: F401

singlestoredb/ai/chat.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def SingleStoreChatFactory(
3939
obo_token_getter: Optional[Callable[[], Optional[str]]] = None,
4040
base_url: Optional[str] = None,
4141
hosting_platform: Optional[str] = None,
42-
timeout: Optional[float] = None,
4342
**kwargs: Any,
4443
) -> Union[ChatOpenAI, ChatBedrockConverse]:
4544
"""Return a chat model instance (ChatOpenAI or ChatBedrockConverse).
@@ -103,10 +102,6 @@ def obo_token_getter_fn() -> Optional[str]:
103102
elif isinstance(t, (int, float)):
104103
connect_timeout = float(t)
105104
read_timeout = float(t)
106-
if timeout is not None:
107-
connect_timeout = timeout
108-
read_timeout = timeout
109-
t = httpx.Timeout(timeout)
110105

111106
if info.hosting_platform == 'Amazon':
112107
# Instantiate Bedrock client

singlestoredb/ai/debugv3.py

Lines changed: 0 additions & 188 deletions
This file was deleted.

singlestoredb/ai/embeddings.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
from collections.abc import Generator
32
from typing import Any
43
from typing import Callable
54
from typing import Optional
@@ -39,7 +38,6 @@ def SingleStoreEmbeddingsFactory(
3938
obo_token_getter: Optional[Callable[[], Optional[str]]] = None,
4039
base_url: Optional[str] = None,
4140
hosting_platform: Optional[str] = None,
42-
timeout: Optional[float] = None,
4341
**kwargs: Any,
4442
) -> Union[OpenAIEmbeddings, BedrockEmbeddings]:
4543
"""Return an embeddings model instance (OpenAIEmbeddings or BedrockEmbeddings).
@@ -103,10 +101,6 @@ def obo_token_getter_fn() -> Optional[str]:
103101
elif isinstance(t, (int, float)):
104102
connect_timeout = float(t)
105103
read_timeout = float(t)
106-
if timeout is not None:
107-
connect_timeout = timeout
108-
read_timeout = timeout
109-
t = httpx.Timeout(timeout)
110104

111105
if info.hosting_platform == 'Amazon':
112106
# Instantiate Bedrock client
@@ -162,38 +156,16 @@ def _inject_headers(request: Any, **_ignored: Any) -> None:
162156
**kwargs,
163157
)
164158

165-
class OpenAIAuth(httpx.Auth):
166-
def auth_flow(
167-
self, request: httpx.Request,
168-
) -> Generator[httpx.Request, None, None]:
169-
if api_key_getter_fn is not None:
170-
token_val = api_key_getter_fn()
171-
if token_val:
172-
request.headers['Authorization'] = f'Bearer {token_val}'
173-
if obo_token_getter_fn is not None:
174-
obo_val = obo_token_getter_fn()
175-
if obo_val:
176-
request.headers['X-S2-OBO'] = obo_val
177-
yield request
178-
179-
if t is not None:
180-
http_client = httpx.Client(
181-
timeout=t,
182-
auth=OpenAIAuth(),
183-
)
184-
else:
185-
http_client = httpx.Client(
186-
timeout=httpx.Timeout(timeout=600, connect=5.0), # default OpenAI timeout
187-
auth=OpenAIAuth(),
188-
)
189-
190159
# OpenAI / Azure OpenAI path
160+
token = api_key_getter_fn()
161+
191162
openai_kwargs = dict(
192163
base_url=info.connection_url,
193-
api_key='placeholder',
164+
api_key=token,
194165
model=model_name,
195166
)
196-
openai_kwargs['http_client'] = http_client
167+
if http_client is not None:
168+
openai_kwargs['http_client'] = http_client
197169
return OpenAIEmbeddings(
198170
**openai_kwargs,
199171
**kwargs,

singlestoredb/ai/utils.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)