Skip to content

Commit abbaf21

Browse files
author
Thomas Baker
committed
add new proxy for the raw_client param
1 parent f366233 commit abbaf21

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/cohere/client_v2.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
from concurrent.futures import ThreadPoolExecutor
88

99

10+
class _CombinedRawClient:
11+
"""Proxy that combines v1 and v2 raw clients.
12+
13+
V2Client and Client both assign to self._raw_client in __init__,
14+
causing a collision when combined in ClientV2/AsyncClientV2.
15+
This proxy delegates to v2 first, falling back to v1 for
16+
legacy methods like generate_stream.
17+
"""
18+
19+
def __init__(self, v1_raw_client: typing.Any, v2_raw_client: typing.Any):
20+
self._v1 = v1_raw_client
21+
self._v2 = v2_raw_client
22+
23+
def __getattr__(self, name: str) -> typing.Any:
24+
try:
25+
return getattr(self._v2, name)
26+
except AttributeError:
27+
return getattr(self._v1, name)
28+
29+
1030
class ClientV2(V2Client, Client): # type: ignore
1131
def __init__(
1232
self,
@@ -32,10 +52,12 @@ def __init__(
3252
thread_pool_executor=thread_pool_executor,
3353
log_warning_experimental_features=log_warning_experimental_features,
3454
)
55+
v1_raw = self._raw_client
3556
V2Client.__init__(
3657
self,
3758
client_wrapper=self._client_wrapper
3859
)
60+
self._raw_client = _CombinedRawClient(v1_raw, self._raw_client)
3961

4062

4163
class AsyncClientV2(AsyncV2Client, AsyncClient): # type: ignore
@@ -63,7 +85,9 @@ def __init__(
6385
thread_pool_executor=thread_pool_executor,
6486
log_warning_experimental_features=log_warning_experimental_features,
6587
)
88+
v1_raw = self._raw_client
6689
AsyncV2Client.__init__(
6790
self,
6891
client_wrapper=self._client_wrapper
6992
)
93+
self._raw_client = _CombinedRawClient(v1_raw, self._raw_client)

0 commit comments

Comments
 (0)