@@ -46,26 +46,12 @@ def __init__(
46
46
"The openai python package is not installed. Please install it with `pip install openai`"
47
47
)
48
48
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 :
53
50
raise ValueError (
54
51
"Please provide an OpenAI API key. You can get one at https://platform.openai.com/account/api-keys"
55
52
)
56
53
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
-
63
54
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
69
55
70
56
self ._v1 = openai .__version__ .startswith ("1." )
71
57
if self ._v1 :
@@ -81,6 +67,21 @@ def __init__(
81
67
api_key = api_key , base_url = api_base , default_headers = default_headers
82
68
).embeddings
83
69
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
+
84
85
self ._client = openai .Embedding
85
86
self ._model_name = model_name
86
87
self ._deployment_id = deployment_id
0 commit comments