我尝试在调用Azure OpenAI GPT时使用functions
,如https://platform.openai.com/docs/api-reference/chat/create#chat/create-functions中所述
我用途:
import openai
openai.api_type = "azure"
openai.api_base = "https://XXXXXXXX.openai.azure.com/"
openai.api_version = "2023-06-01-preview"
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.ChatCompletion.create(
engine="gpt-35-turbo-XXX",
model="gpt-35-turbo-0613-XXXX"
messages=messages,
functions=functions,
function_call="auto",
)
字符串
但我得到了错误:
openai.error.InvalidRequestError:
Unrecognized request argument supplied: functions
型
为什么?为什么?
运行上面示例代码的数据(需要定义messages
和functions
):
messages = [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello!"}]
functions = [
{
"name": "fetch_pages",
"description": "Fetch the content of specified pages from the document.",
"parameters": {
"type": "object",
"properties": {
"pages": {
"type": "array",
"items": {
"type": "number"
},
"description": "The list of pages to fetch."
}
},
"required": ["pages"]
}
},
{
"name": "fetch_section",
"description": "Fetch the content of a specified section.",
"parameters": {
"type": "object",
"properties": {
"section_title": {
"type": "string",
"description": "The title of the section to fetch."
}
},
"required": ["section_title"]
}
},
{
"name": "search",
"description": "Search the document for a string query.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The search term."
}
},
"required": ["query"]
}
}
]
型
2条答案
按热度按时间dl5txlt91#
Azure API的函数支持已在2023-07-01-preview中添加。示例中的API版本需要更新:
字符串
lokaqttq2#
作为对Krista答案的补充,它seems,一个人必须使用最新的0613版本的
gpt-35-turbo
和gpt-4
。示例代码:
字符串
输出量:
型