mem0ai / mem0

The Memory layer for your AI apps
https://mem0.ai
Apache License 2.0
22.79k stars 2.09k forks source link

azure_openai support stopped in embedders validation in v0.0.92 to 0.1.1 #925

Closed ghoshaishik505 closed 11 months ago

ghoshaishik505 commented 1 year ago

🐛 azure_openai embedder: validation of config.yaml with azure_openai fails from in v0.0.92 to v0.1.1

When using azure openai's embedding functions, the config.yaml is

llm:
  provider: azure_openai
  config:
    model: gpt-35-turbo
    deployment_name: your_llm_deployment_name
    temperature: 0.5
    max_tokens: 1000
    top_p: 1
    stream: false

embedder:
  provider: azure_openai
  config:
    model: text-embedding-ada-002
    deployment_name: you_embedding_model_deployment_name

The last few versions validate this yaml file, and throws Key 'provider' error: Or('openai', 'gpt4all', 'huggingface', 'vertexai') did not validate 'azure_openai')

Please add 'azure_openai' options in the validations.

deshraj commented 1 year ago

Thanks for reporting. We are working on it.

sidmohanty11 commented 1 year ago

@ghoshaishik505 thanks for reporting this, this is fixed in the newest release.♥️

ghoshaishik505 commented 1 year ago

@sidmohanty11 thanks for the update. Checked in the newest version(0.1.5), the validation passes. But Azure OpenAI Embeddings still doesn't work as for embedding, its still using the OpenAIEmbeddings class, and the keys and details are searched in the OpenAI platform instead of Azure OpenAI. Giving the full logs here, faced with the quickstart sample code in the docs. Please note the warning as well.

''' MyDir/env/lib/python3.10/site-packages/langchain/embeddings/openai.py:320: UserWarning: If you have openai>=1.0.0 installed and are using Azure, please use the AzureOpenAIEmbeddings class. warnings.warn( Adding Data Traceback (most recent call last): File "MyDir/sample.py", line 6, in app.add("https://en.wikipedia.org/wiki/Elon_Musk") File "MyDir/env/lib/python3.10/site-packages/embedchain/embedchain.py", line 206, in add documents, metadatas, _ids, new_chunks = self.load_and_embed( File "MyDir/env/lib/python3.10/site-packages/embedchain/embedchain.py", line 438, in load_and_embed self.db.add( File "MyDir/env/lib/python3.10/site-packages/embedchain/vectordb/elasticsearch.py", line 125, in add embeddings = self.embedder.embedding_fn(documents) File "MyDir/env/lib/python3.10/site-packages/embedchain/embedder/base.py", line 70, in embed_function return embeddings.embed_documents(texts) File "MyDir/env/lib/python3.10/site-packages/langchain/embeddings/openai.py", line 549, in embed_documents return self._get_len_safe_embeddings(texts, engine=self.deployment) File "MyDir/env/lib/python3.10/site-packages/langchain/embeddings/openai.py", line 426, in _get_len_safe_embeddings response = embed_with_retry( File "MyDir/env/lib/python3.10/site-packages/langchain/embeddings/openai.py", line 109, in embed_with_retry return embeddings.client.create(kwargs) File "MyDir/env/lib/python3.10/site-packages/openai/resources/embeddings.py", line 105, in create return self._post( File "MyDir/env/lib/python3.10/site-packages/openai/_base_client.py", line 1055, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) File "MyDir/env/lib/python3.10/site-packages/openai/_base_client.py", line 834, in request return self._request( File "MyDir/env/lib/python3.10/site-packages/openai/_base_client.py", line 877, in _request raise self._make_status_error_from_response(err.response) from None openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: asdfghjk**1w32. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}} '''

Thanks

ghoshaishik505 commented 12 months ago

@sidmohanty11 , any luck with this?

ghoshaishik505 commented 12 months ago

Please have a look in the recent logs: With Chroma: """ /MyDir/MyBot//env/lib/python3.10/site-packages/langchain/embeddings/openai.py:320: UserWarning: If you have openai>=1.0.0 installed and are using Azure, please use the AzureOpenAIEmbeddings class. warnings.warn( Traceback (most recent call last): File "/MyDir/MyBot//sample.py", line 2, in app = App.from_config(yaml_path="config.yaml") File "/MyDir/MyBot//env/lib/python3.10/site-packages/embedchain/pipeline.py", line 397, in from_config return cls( File "/MyDir/MyBot//env/lib/python3.10/site-packages/embedchain/pipeline.py", line 114, in init self._init_db() File "/MyDir/MyBot//env/lib/python3.10/site-packages/embedchain/pipeline.py", line 151, in _init_db self.db._initialize() File "/MyDir/MyBot//env/lib/python3.10/site-packages/embedchain/vectordb/chroma.py", line 71, in _initialize self._get_or_create_collection(self.config.collection_name) File "/MyDir/MyBot//env/lib/python3.10/site-packages/embedchain/vectordb/chroma.py", line 100, in _get_or_create_collection self.collection = self.client.get_or_create_collection( File "/MyDir/MyBot//env/lib/python3.10/site-packages/chromadb/api/client.py", line 226, in get_or_create_collection return self._server.get_or_create_collection( File "/MyDir/MyBot//env/lib/python3.10/site-packages/chromadb/telemetry/opentelemetry/init.py", line 127, in wrapper return f(*args, *kwargs) File "/MyDir/MyBot//env/lib/python3.10/site-packages/chromadb/api/segment.py", line 216, in get_or_create_collection return self.create_collection( # type: ignore File "/MyDir/MyBot//env/lib/python3.10/site-packages/chromadb/telemetry/opentelemetry/init.py", line 127, in wrapper return f(args, **kwargs) File "/MyDir/MyBot//env/lib/python3.10/site-packages/chromadb/api/segment.py", line 190, in create_collection return Collection( File "/MyDir/MyBot//env/lib/python3.10/site-packages/chromadb/api/models/Collection.py", line 85, in init validate_embedding_function(embedding_function) File "/MyDir/MyBot//env/lib/python3.10/site-packages/chromadb/api/types.py", line 210, in validate_embedding_function raise ValueError( ValueError: Expected EmbeddingFunction.call to have the following signature: odict_keys(['self', 'input']), got odict_keys(['self', 'args', 'kwargs']) Please see https://docs.trychroma.com/embeddings for details of the EmbeddingFunction interface. Please note the recent change to the EmbeddingFunction interface: https://docs.trychroma.com/migration#migration-to-0416---november-7-2023

"""

With Elastic Search:

""" /MyDir/MyBot/env/lib/python3.9/site-packages/langchain/embeddings/openai.py:320: UserWarning: If you have openai>=1.0.0 installed and are using Azure, please use the AzureOpenAIEmbeddings class. warnings.warn( Creating index es-em-0115_1536 {'mappings': {'properties': {'text': {'type': 'text'}, 'embeddings': {'type': 'dense_vector', 'index': False, 'dims': 1536}}}} Adding Data Traceback (most recent call last): File "/MyDir/MyBot/sample.py", line 6, in app.add("https://en.wikipedia.org/wiki/Elon_Musk") File "/MyDir/MyBot/env/lib/python3.9/site-packages/embedchain/embedchain.py", line 206, in add documents, metadatas, _ids, new_chunks = self._load_and_embed( File "/MyDir/MyBot/env/lib/python3.9/site-packages/embedchain/embedchain.py", line 438, in _load_and_embed self.db.add( File "/MyDir/MyBot/env/lib/python3.9/site-packages/embedchain/vectordb/elasticsearch.py", line 125, in add embeddings = self.embedder.embedding_fn(documents) File "/MyDir/MyBot/env/lib/python3.9/site-packages/embedchain/embedder/base.py", line 70, in embed_function return embeddings.embed_documents(texts) File "/MyDir/MyBot/env/lib/python3.9/site-packages/langchain/embeddings/openai.py", line 549, in embed_documents return self._get_len_safe_embeddings(texts, engine=self.deployment) File "/MyDir/MyBot/env/lib/python3.9/site-packages/langchain/embeddings/openai.py", line 426, in _get_len_safe_embeddings response = embed_with_retry( File "/MyDir/MyBot/env/lib/python3.9/site-packages/langchain/embeddings/openai.py", line 109, in embed_with_retry return embeddings.client.create(kwargs) File "/MyDir/MyBot/env/lib/python3.9/site-packages/openai/resources/embeddings.py", line 105, in create return self._post( File "/MyDir/MyBot/env/lib/python3.9/site-packages/openai/_base_client.py", line 1055, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) File "/MyDir/MyBot/env/lib/python3.9/site-packages/openai/_base_client.py", line 834, in request return self._request( File "/MyDir/MyBot/env/lib/python3.9/site-packages/openai/_base_client.py", line 877, in _request raise self._make_status_error_from_response(err.response) from None openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: asdfghjk****1w32. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}} """

@deshraj @sidmohanty11 , probably its better to merge these two issues: https://github.com/embedchain/embedchain/issues/926

sidmohanty11 commented 12 months ago

Thanks a lot @ghoshaishik505 ! This is definitely in our radar, will target to fix this soon next week