I seem unable to consume my Azure OpenAI API. The model is deployed. I’m getting the following error message:
“openai.error.InvalidRequestError: Must provide an ‘engine’ or ‘deployment_id’ parameter to create a <class ‘openai.api_resources.chat_completion.ChatCompletion’>”
import openai
import os
import load_dotenv
'''
AZURE_OPENAI_RESOURCE = 'AI_Sandbox'
AZURE_OPENAI_MODEL = 'gpt-3.5-turbo'
AZURE_OPENAI_KEY = ''
AZURE_OPENAI_ENDPOINT = 'https://{resource}.openai.azure.com/'
AZURE_OPENAI_MODEL_NAME = 'gpt-35-turbo'
AZURE_DEPLOYMENT_NAME = 'GPT-35-TURBO'
'''
# AOAI Integration Settings
AZURE_OPENAI_RESOURCE = os.environ.get("AZURE_OPENAI_RESOURCE")
AZURE_OPENAI_MODEL = os.environ.get("AZURE_OPENAI_MODEL")
AZURE_OPENAI_MODEL_NAME = os.environ.get("AZURE_OPENAI_MODEL_NAME")
AZURE_OPENAI_ENDPOINT = os.environ.get("AZURE_OPENAI_ENDPOINT")
AZURE_OPENAI_KEY = os.environ.get("AZURE_OPENAI_KEY")
AZURE_DEPLOYMENT_NAME = os.environ.get("AZURE_DEPLOYMENT_NAME")
base_url = AZURE_OPENAI_ENDPOINT if AZURE_OPENAI_ENDPOINT else f"https://{AZURE_OPENAI_RESOURCE}.openai.azure.com/"
class OpenAIService:
def __init__(self):
openai.api_key = AZURE_OPENAI_KEY
openai.api_type = "azure"
openai.api_base = base_url
openai.api_version = "2023-03-15-preview"
def list_models(self):
return openai.Model.list()
def prompt(self, prompt):
return openai.ChatCompletion.create(
engine=AZURE_OPENAI_MODEL_NAME,
deployment_id=AZURE_DEPLOYMENT_NAME,
messages=[{"role": "user", "content": prompt}],
temperature=0,
timeout=60,
)
Based on the provided information, it seems the issue is you are passing
seems both
engine
anddeployment_id
takedeployment name
as input value (You can use either of these parameter).Below is the update code snippet:
With this I was able to get the required results: