Having Problems with AzureChatOpenAI()

152 views Asked by At

people. I'm trying to use the AzureChatOpenAI(), but even if I put the right parameters, it doesn't work. Here it is:

from langchain_core.messages import HumanMessage
from langchain_openai import AzureChatOpenAI
import os

os.environ['AZURE_OPENAI_DEPLOYMENT_NAME'] = "..."
os.environ["AZURE_OPENAI_API_KEY"] = "..."
os.environ["AZURE_OPENAI_ENDPOINT"] = "https://xxx.openai.azure.com/"
os.environ["AZURE_OPENAI_API_VERSION"] = "2024-02-15-preview"

model = AzureChatOpenAI(
            temperature=0,
            deployment_name=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"],
            azure_endpoint="AZURE_OPENAI_ENDPOINT",
            api_version=os.environ["AZURE_OPENAI_API_VERSION"],
            openai_api_key=os.environ["AZURE_OPENAI_API_KEY"],
            streaming=True,
)

And the error:

ValidationError: 1 validation error for AzureChatOpenAI
__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)

Does someone had this same error? Do you know how to fix this?

Even if I put azure_endpoint until openai_api_base, it gives me the same ValidationError. I tried a lot of things but nothing worked at all.

1

There are 1 answers

0
user459872 On

I think you have configured the OPENAI_API_BASE environment variable. It's value will be automatically taken for openai_api_base. And that's what the error message(marked in bold) trying to say.

Azure endpoints should be specified via the `azure_endpoint` 
param not `openai_api_base` (or alias `base_url`). (type=value_error)

Either delete this enviorment variable(OPENAI_API_BASE) or add

del os.environ["OPENAI_API_BASE"]

just before creating AzureChatOpenAI instance.