我似乎无法使用我的Azure OpenAI API。模型已部署。我收到以下错误消息:
“openai.error.InvalidRequestError:必须提供resources.chat”
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,
)
1条答案
按热度按时间wa7juj8i1#
根据提供的信息,似乎问题是你正在通过
似乎
engine
和deployment_id
都将deployment name
作为输入值(您可以使用其中任何一个参数)。下面是更新代码片段:
这样,我就得到了所需的结果: