Skip to content

Commit

Permalink
EmbedderAzureOpenAIConfig use langchain.embeddings.OpenAIEmbeddings
Browse files Browse the repository at this point in the history
Do not use the Fake Embeddings anymore.
Requires LangChain 0.0.155 because it contains langchain-ai/langchain#3711
  • Loading branch information
zioproto committed May 2, 2023
1 parent e00a8fb commit 4ef1a79
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
9 changes: 5 additions & 4 deletions core/cat/factory/embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ class Config:
"description": "Configuration for OpenAI embeddings",
}

# https://python.langchain.com/en/latest/_modules/langchain/embeddings/openai.html#OpenAIEmbeddings
class EmbedderAzureOpenAIConfig(EmbedderSettings):
openai_api_key: str
model_name: str
api_base: str
model: str
openai_api_base: str
api_type: str
api_version: str
deployment_name: str
deployment: str

_pyclass: PyObject = langchain.embeddings.FakeEmbeddings
_pyclass: PyObject = langchain.embeddings.OpenAIEmbeddings

class Config:
schema_extra = {
Expand Down
4 changes: 3 additions & 1 deletion core/cat/factory/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ class Config:
# https://python.langchain.com/en/latest/modules/models/llms/integrations/azure_openai_example.html
class LLMAzureOpenAIConfig(LLMSettings):
openai_api_key: str
api_base: str
openai_api_base: str
api_type: str = "azure"
# https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#completions
# Current supported versions 2022-12-01 or 2023-03-15-preview
api_version: str = "2022-12-01"
deployment_name: str = "text-davinci-003"
model_name: str = "text-davinci-003"
Expand Down
16 changes: 13 additions & 3 deletions core/cat/mad_hatter/core_plugin/hooks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,20 @@ def get_language_embedder(cat):
}
)
else:
print(cat.llm)
embedder = embedders.EmbedderAzureOpenAIConfig.get_embedder_from_config(
{"size": 1536} # mock openai embedding size

{
"openai_api_key": openai_key,
"openai_api_type": "azure",
"model": "text-embedding-ada-002",
# Now the only model for embeddings is text-embedding-ada-002
# It is also possible to use the Azure "deployment" name that is user defined
# when the model is deployed to Azure.
# "deployment": "my-text-embedding-ada-002",
"openai_api_base": cat.llm.openai_api_base,
# https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#embeddings
# current supported versions 2022-12-01 or 2023-03-15-preview
"openai_api_version": "2022-12-01",
}
)
elif "COHERE_KEY" in os.environ:
embedder = embedders.EmbedderCohereConfig.get_embedder_from_config(
Expand Down
4 changes: 2 additions & 2 deletions core/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ sqlmodel==0.0.8
pandas==1.5.3
scikit-learn==1.2.1
qdrant_client==1.1.2
langchain==0.0.121
openai==0.27.0
langchain==0.0.155
openai==0.27.5
cohere==4.0.4
huggingface-hub==0.13.2
beautifulsoup4==4.12.0
Expand Down

0 comments on commit 4ef1a79

Please sign in to comment.