I tried using below code with a sample Azure OpenAPI and it worked successfully.
Code:-
# Import Azure OpenAI
from langchain.llms import AzureOpenAI
import openai
import os
# os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_KEY"] = "<open-api-key>"
os.environ["OPENAI_API_BASE"] = "https://xxxxx.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"))
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.
You can verify the endpoint by visiting :-
Azure OpenAI Studio > Playground > Code view or by visiting your OpenAI resource on azure in the Resource management section
Refer this Github MS document for the details mentioned above and run the code of
this github repo:- azure-docs/python.md at main ·
MicrosoftDocs/azure-docs ·
GitHub
Get the deployment model from the model you deployed while creating
the resource- Refer this MS document here-
https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal Make sure the model name is correct as that also causes resource not found error like below:-
Error:-
openai.error.InvalidRequestError: The model `text-davin-043` does not exist
Additionally check if there's any space or character after your api
base key try deleting it and run the code again and refer other
solutions mentioned in this MS forum regarding the same error code :-
Open AI error: "InvalidRequestError: Resource not found". Please help
to fix. - Microsoft
Q&A