[BUG] AuthenticationError of creating an OpenAIEmbedding Instance when utilize an OpenAI proxy service
Tsumugii24 opened this issue · 0 comments
Required prerequisites
- I have read the documentation https://camel-ai.github.io/camel/camel.html.
- I have searched the Issue Tracker and Discussions that this hasn't already been reported. (+1 or comment there if it has.)
- Consider asking first in a Discussion.
What version of camel are you using?
0.1.6.9
System information
3.10.14 | packaged by Anaconda, Inc. | (main, May 6 2024, 19:44:50) [MSC v.1916 64 bit (AMD64)] win32
0.1.6.9
Problem description
AuthenticationError will be raised when creating an OpenAIEmbedding instance when utilize an OpenAI proxy service.
To be more specific, the key argument OPENAI_API_BASE_URL is not considered in openai_embedding.py
.
Reproducible example code
The Python snippets:
from camel.embeddings import OpenAIEmbedding
openai_api_key = "your api key"
openai_base_url = "your base url"
os.environ["OPENAI_API_KEY"] = openai_api_key
os.environ["OPENAI_API_BASE_URL"] = openai_base_url
embedding_model=OpenAIEmbedding()
text = "camel"
vector = embedding_model.embed(text)
Command lines:
(camel) PS C:\Users\YUI\.cursor-tutor\projects> python .\main.py
Traceback (most recent call last):
File "C:\Users\YUI\.cursor-tutor\projects\main.py", line 11, in <module>
vector = embedding_model.embed(text)
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\camel\embeddings\base.py", line 58, in embed
return self.embed_list([obj], **kwargs)[0]
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\camel\utils\commons.py", line 269, in wrapper
return func(self, *args, **kwargs)
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\camel\embeddings\openai_embedding.py", line 78, in embed_list
response = self.client.embeddings.create(
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\openai\resources\embeddings.py", line 114, in create
return self._post(
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\openai\_base_client.py", line 1260, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\openai\_base_client.py", line 937, in request
return self._request(
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\openai\_base_client.py", line 1041, in _request
raise self._make_status_error_from_response(err.response) from None
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-XA0vI***************************************6fF9. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}
Steps to reproduce:
- set
OPENAI_API_KEY
andOPENAI_API_BASE_URL
- create an instance of
OpenAIEmbedding
- call its
embed
method
Traceback
Traceback (most recent call last):
File "C:\Users\YUI\.cursor-tutor\projects\main.py", line 11, in <module>
vector = embedding_model.embed(text)
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\camel\embeddings\base.py", line 58, in embed
return self.embed_list([obj], **kwargs)[0]
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\camel\utils\commons.py", line 269, in wrapper
return func(self, *args, **kwargs)
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\camel\embeddings\openai_embedding.py", line 78, in embed_list
response = self.client.embeddings.create(
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\openai\resources\embeddings.py", line 114, in create
return self._post(
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\openai\_base_client.py", line 1260, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\openai\_base_client.py", line 937, in request
return self._request(
File "C:\ProgramData\Anaconda3\envs\camel\lib\site-packages\openai\_base_client.py", line 1041, in _request
raise self._make_status_error_from_response(err.response) from None
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-XA0vI***************************************6fF9. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}
Expected behavior
If I set os.environ["OPENAI_API_BASE_URL"]
in the environment variables, then after instantiating OpenAIEmbedding()
, it can be used directly. Alternatively, a new optional url
parameter can be added, allowing the user to manually specify it when instantiating the embedding model, such as OpenAIEmbedding(url="your base url")
.
Additional context
No response