I’m trying to use LangChain’s AzureOpenAI as below but getting this error.
Do you know how can I fix this?
openai.error.InvalidRequestError: Resource not found
# Import Azure OpenAI
from langchain.llms import AzureOpenAI
import openai
import os
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_KEY"] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
os.environ["OPENAI_API_BASE"] = "https://XXXXXX-openai.openai.azure.com/"
os.environ["OPENAI_API_VERSION"] = "2022-12-01"
llm = AzureOpenAI(
openai_api_type="azure",
deployment_name="text-davinci-003",
model_name="text-davinci-003")
print(llm("hi"))
Use Azure OpenAI with LangChain framework
2
Answers
I tried using below code with a sample Azure OpenAPI and it worked successfully.
Code:-
Output:-
Another output:-
Double check if your OpenAPI key and Azure Open AI Endpoint that you have entered in the os.env code is missing any string or characters. Make sure the endpoint you are using for Azure is correct and not invalid.
What worked for me was removing the import of
openai
when using thelangchain.llms.AzureOpenAI
module.In you example, try removing line 3
import openai
In my code, I also did not include
openai_api_type="azure"
since it is already set as an environment variable.