Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] AuthenticationError of creating an OpenAIEmbedding Instance when utilize an OpenAI proxy service #897

Open
3 tasks done
Tsumugii24 opened this issue Sep 5, 2024 · 0 comments · May be fixed by #898
Open
3 tasks done
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Tsumugii24
Copy link

Tsumugii24 commented Sep 5, 2024

Required prerequisites

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:

  1. set OPENAI_API_KEY and OPENAI_API_BASE_URL
  2. create an instance of OpenAIEmbedding
  3. 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

@Tsumugii24 Tsumugii24 added the bug Something isn't working label Sep 5, 2024
@Wendong-Fan Wendong-Fan assigned Tsumugii24 and unassigned lightaime Sep 6, 2024
@Wendong-Fan Wendong-Fan added this to the Sprint 11 milestone Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
3 participants