Skip to content

Commit e61a13b

Browse files
committed
fix for new openai 1.20.0 version
1 parent 7e48162 commit e61a13b

File tree

2 files changed

+54
-24
lines changed

2 files changed

+54
-24
lines changed

typegpt/openai/_async/client.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
from typing import Mapping
23

34
import httpx
@@ -25,6 +26,7 @@ def __init__(
2526
*,
2627
api_key: str | None = None,
2728
organization: str | None = None,
29+
project: str | None = None,
2830
base_url: str | httpx.URL | None = None,
2931
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
3032
max_retries: int = DEFAULT_MAX_RETRIES,
@@ -35,18 +37,31 @@ def __init__(
3537
# only needed to have same subclass capabilities (i.e. for Azure)
3638
_strict_response_validation: bool = False,
3739
) -> None:
38-
super().__init__(
39-
api_key=api_key,
40-
organization=organization,
41-
base_url=base_url,
42-
timeout=timeout,
43-
max_retries=max_retries,
44-
default_headers=default_headers,
45-
default_query=default_query,
46-
http_client=http_client,
47-
)
40+
init_signature = inspect.signature(super.__init__)
41+
if "project" in init_signature.parameters: # openai version >= 1.20.0
42+
super().__init__(
43+
api_key=api_key,
44+
organization=organization,
45+
project=project,
46+
base_url=base_url,
47+
timeout=timeout,
48+
max_retries=max_retries,
49+
default_headers=default_headers,
50+
default_query=default_query,
51+
http_client=http_client,
52+
)
53+
else:
54+
super().__init__(
55+
api_key=api_key,
56+
organization=organization,
57+
base_url=base_url,
58+
timeout=timeout,
59+
max_retries=max_retries,
60+
default_headers=default_headers,
61+
default_query=default_query,
62+
http_client=http_client,
63+
)
4864
self.chat = AsyncTypeChat(self)
4965

5066

51-
class AsyncTypeAzureOpenAI(AsyncAzureOpenAI, AsyncTypeOpenAI):
52-
...
67+
class AsyncTypeAzureOpenAI(AsyncAzureOpenAI, AsyncTypeOpenAI): ...

typegpt/openai/_sync/client.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
from typing import Mapping
23

34
import httpx
@@ -25,6 +26,7 @@ def __init__(
2526
*,
2627
api_key: str | None = None,
2728
organization: str | None = None,
29+
project: str | None = None,
2830
base_url: str | httpx.URL | None = None,
2931
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
3032
max_retries: int = DEFAULT_MAX_RETRIES,
@@ -35,18 +37,31 @@ def __init__(
3537
# only needed to have same subclass capabilities (i.e. for Azure)
3638
_strict_response_validation: bool = False,
3739
) -> None:
38-
super().__init__(
39-
api_key=api_key,
40-
organization=organization,
41-
base_url=base_url,
42-
timeout=timeout,
43-
max_retries=max_retries,
44-
default_headers=default_headers,
45-
default_query=default_query,
46-
http_client=http_client,
47-
)
40+
init_signature = inspect.signature(super.__init__)
41+
if "project" in init_signature.parameters: # openai version >= 1.20.0
42+
super().__init__(
43+
api_key=api_key,
44+
organization=organization,
45+
project=project,
46+
base_url=base_url,
47+
timeout=timeout,
48+
max_retries=max_retries,
49+
default_headers=default_headers,
50+
default_query=default_query,
51+
http_client=http_client,
52+
)
53+
else:
54+
super().__init__(
55+
api_key=api_key,
56+
organization=organization,
57+
base_url=base_url,
58+
timeout=timeout,
59+
max_retries=max_retries,
60+
default_headers=default_headers,
61+
default_query=default_query,
62+
http_client=http_client,
63+
)
4864
self.chat = TypeChat(self)
4965

5066

51-
class TypeAzureOpenAI(AzureOpenAI, TypeOpenAI):
52-
...
67+
class TypeAzureOpenAI(AzureOpenAI, TypeOpenAI): ...

0 commit comments

Comments
 (0)