Skip to content

Commit 387e351

Browse files
committed
[BUG] Modify attributes of openai only when using openai 0.x
1 parent 28b3739 commit 387e351

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

chromadb/utils/embedding_functions/openai_embedding_function.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,12 @@ def __init__(
4646
"The openai python package is not installed. Please install it with `pip install openai`"
4747
)
4848

49-
if api_key is not None:
50-
openai.api_key = api_key
51-
# If the api key is still not set, raise an error
52-
elif openai.api_key is None:
49+
if api_key is None and openai.api_key is None:
5350
raise ValueError(
5451
"Please provide an OpenAI API key. You can get one at https://platform.openai.com/account/api-keys"
5552
)
5653

57-
if api_base is not None:
58-
openai.api_base = api_base
59-
60-
if api_version is not None:
61-
openai.api_version = api_version
62-
6354
self._api_type = api_type
64-
if api_type is not None:
65-
openai.api_type = api_type
66-
67-
if organization_id is not None:
68-
openai.organization = organization_id
6955

7056
self._v1 = openai.__version__.startswith("1.")
7157
if self._v1:
@@ -81,6 +67,21 @@ def __init__(
8167
api_key=api_key, base_url=api_base, default_headers=default_headers
8268
).embeddings
8369
else:
70+
if api_key is not None:
71+
openai.api_key = api_key
72+
73+
if api_base is not None:
74+
openai.api_base = api_base
75+
76+
if api_version is not None:
77+
openai.api_version = api_version
78+
79+
if api_type is not None:
80+
openai.api_type = api_type
81+
82+
if organization_id is not None:
83+
openai.organization = organization_id
84+
8485
self._client = openai.Embedding
8586
self._model_name = model_name
8687
self._deployment_id = deployment_id

0 commit comments

Comments
 (0)