Closed loomlike closed 2 weeks ago
Have you tried specifying everything when you create the model? For example:
model = AzureChatOpenAI(
openai_api_version="2023-05-15",
azure_deployment=os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME"),
temperature=0,
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
)
Not sure if this would work but give it a try.
I have the exact same problem as OP, and no, that does not work.
Environment variables
# azure openai (embedding API)
AZURE_OPENAI_ENDPOINT=my_endpoint
AZURE_OPENAI_API_KEY=my_key
# OPENAI_API_BASE=my_endpoint
# OPENAI_API_KEY=my_key
AZURE_OPENAI_EMBEDDINGS=my_embedding
OPENAI_API_VERSION=my_version
OPENAI_API_TYPE=azure
Code
import os
from langchain_openai import AzureOpenAIEmbeddings
from dotenv import load_dotenv
load_dotenv('azure.env')
embeddings = AzureOpenAIEmbeddings(
azure_endpoint=os.environ["AZURE_OPENAI_ENDPOINT"],
api_key=os.environ["AZURE_OPENAI_API_KEY"],
azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS"])
text = "Hello, world!"
query_result = embeddings.embed_query(text)
print(query_result)
In azure.env, if comment out OPEN_API_BASE, the code works. If I uncomment it, I get the same exact error that OP sees.
ValidationError: 1 validation error for AzureOpenAIEmbeddings
__root__
As of openai>=1.0.0, Azure endpoints should be specified via the `azure_endpoint` param not `openai_api_base` (or alias `base_url`). (type=value_error)
So no, specifying the endpoint as an argument does not fix this problem.
#pip freeze | grep 'langchain\|openai'
langchain==0.2.0
langchain-cli==0.0.22
langchain-community==0.2.0
langchain-core==0.2.1
langchain-experimental==0.0.59
langchain-openai==0.1.7
langchain-text-splitters==0.2.0
openai==1.30.1
openai-core==0.19.1
openai-schema-validator==0.6.2
openai-spec-validator==0.7.1
Just submitted a PR with a fix
Checked other resources
Example Code
Environment variables:
Code to cause the error:
Error Message and Stack Trace (if applicable)
Description
AzureOpenAIEmbeddings
andAzureChatOpenAI
automatically pick up the env vars and throwing errors complaining about having bothazure_endpoint
param andopenai_api_base
.OPENAI_API_BASE
env var is being used in other packages, like MLFlow.System Info