Having Problems with AzureChatOpenAI()

2024/10/7 22:29:10

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 osos.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.

Answer

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.

https://en.xdnf.cn/q/118772.html

Related Q&A

Finding cycles in a dictionary

I have a dictionary which has values as:m = {1: 2, 7: 3, 2: 1, 4: 4, 5: 3, 6: 9}The required output should be cyclic values like 1:2 -> 2:1 = cycle, which both are present in dictionary. 4:4 is also…

Create a dataframe from HTML table in Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 9…

Unable to load a Django model from a separate directory in a database script

I am having difficulty writing a python script that takes a directory of .txt files and loads them into my database that is utilized in a Django project. Based on requirements the python script needs …

Leetcode problem 14. Longest Common Prefix (Python)

I tried to solve the problem (you can read description here: https://leetcode.com/problems/longest-common-prefix/) And the following is code I came up with. It gives prefix value of the first string in…

Python BS: Fetching rows with and without color attribute

I have some html that looks like this (this represents rows of data in a table, i.e the data between tr and /tr is one row in a table)<tr bgcolor="#f4f4f4"> <td height="25"…

Python multiple number guessing game

I am trying to create a number guessing game with multiple numbers. The computer generates 4 random numbers between 1 and 9 and then the user has 10 chances to guess the correct numbers. I need the fee…

How to produce a graph of connected data in Python?

Lets say I have a table of words, and each word has a "related words" column. In practice, this would probably be two tables with a one-to-many relationship, as each word can have more than o…

Syntax for reusable iterable?

When you use a generator comprehension, you can only use the iterable once. For example.>>> g = (i for i in xrange(10)) >>> min(g) 0 >>> max(g) Traceback (most recent call la…

Buildozer Problem. I try to make apk file for android, but i cant

artur@DESKTOP-SMKQONQ:~/Suka$ lsbuildozer.spec main.pyartur@DESKTOP-SMKQONQ:~/Suka$ buildozer android debugTraceback (most recent call last):File "/usr/local/bin/buildozer", line 10, in <…

how to run python script with ansible-playbook?

I want to print result in ansible-playbook but not working. python script: #!/usr/bin/python3import timewhile True:print("Im alive")time.sleep(5)deploy_python_script.yml:connection: localbeco…