langchain
langchain copied to clipboard
OpenAIEmbeddings Unsupported OpenAI-Version header provided: 2022-12-01
System Info
langchain-0.0.158 Python 3.11.2 macos
Who can help?
@hwchase17
Information
- [ ] The official example notebooks/scripts
- [X] My own modified scripts
Related Components
- [ ] LLMs/Chat Models
- [X] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async
Reproduction
from langchain.embeddings import OpenAIEmbeddings
import os
import openai
openai.debug = True
openai.log = 'debug'
os.environ["OPENAI_API_TYPE"] = "open_ai"
text = "This is a test query."
embeddings = OpenAIEmbeddings(
model="text-embedding-ada-002",
)
query_result = embeddings.embed_query(text)
print(query_result)
Expected behavior
I got this error:
error_code=None error_message='Unsupported OpenAI-Version header provided: 2022-12-01. (HINT: you can provide any of the following supported versions: 2020-10-01, 2020-11-07. Alternatively, you can simply omit this header to use the default version associated with your account.)' error_param=headers:openai-version error_type=invalid_request_error message='OpenAI API error received' stream_error=False
Traceback (most recent call last):
File "/Users/leeoxiang/Code/openai-play/hello_world/embeding.py", line 33, in <module>
query_result = embeddings.embed_query(text)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/langchain/embeddings/openai.py", line 280, in embed_query
embedding = self._embedding_func(text, engine=self.deployment)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/langchain/embeddings/openai.py", line 250, in _embedding_func
return embed_with_retry(self, input=[text], engine=engine)["data"][0][
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/langchain/embeddings/openai.py", line 63, in embed_with_retry
return _embed_with_retry(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py", line 289, in wrapped_f
return self(f, *args, **kw)
^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py", line 379, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/lib/python3.11/site-packages/tenacity/__init__.py", line 314, in iter
return fut.result()
^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
I got same error when i upgrade langchain = 0.0.158
openai.error.InvalidRequestError: Unsupported OpenAI-Version header provided: 2022-12-01.
(HINT: you can provide any of the following supported versions: 2020-10-01, 2020-11-07.
Alternatively, you can simply omit this header to use the default version associated with your account.)
I find a commit https://github.com/hwchase17/langchain/pull/3942/commits/e2e05235ddf60dafe949c523c9f5d42ff589d098 to add this line to langchain to support for Azure OpenAI Service custom endpoint
openai_api_version: str = "2022-12-01"
maybe, this is only support for Azure OpenAI Service.
I add version when i init OpenAIEmbeddings : OpenAIEmbeddings(openai_api_version='2020-11-07')
or, can set openai_api_version
in env.
I had the same problem when I deployed on streamlit, then I restricted langchain == 0.0.157
and added in the code
openai.api_version = '2020-11-07'
os.environ["OPENAI_API_VERSION"] = '2020-11-07'
But it doesn't solve the problem
Here is a temporary solution: placing openai.api_version = '2020-11-07'
just before openai.ChatCompletion.create
like this:
messages = [{"role": "user", "content": prompt}]
openai.api_version = '2020-11-07'
response = openai.ChatCompletion.create(
model=model,
messages=messages, # temperature=temperature, # this is the model,
temperature=temperature,
)
Hi, @notedit! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, the issue you reported is related to the OpenAIEmbeddings script throwing an error due to an unsupported OpenAI-Version header provided. Users have tried different solutions such as downgrading the langchain version or setting the openai_api_version in the code or environment variables, but these solutions did not solve the problem. However, a temporary solution suggested by a user is to place openai.api_version = '2020-11-07'
just before openai.ChatCompletion.create
in the code, which seems to have resolved the error caused by the unsupported OpenAI-Version header.
Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!