我目前正在使用 Node.js 的 @azure/openai npm 包与 GPT-4 模型进行交互。我注意到响应中的 toolCalls 是空的,即使我在请求中包含了工具。
代码:
const getCurrentWeather = {
name: 'get_current_weather',
description: 'Get the current weather in a given location',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
unit: {
type: 'string',
enum: ['celsius', 'fahrenheit'],
},
},
required: ['location'],
},
};
const messages = [{ role: 'user', content: 'What is the weather like in Glasgow Scotland?' }];
const options = {
tools: [
{
type: 'function',
function: getCurrentWeather,
},
],
};
client.getChatCompletions(deploymentIdBest, messages, options).then((res) => console.log(res));
预期行为: 当然,我们期望得到这样的回应:
{'role': 'assistant',
'content': None,
'tool_calls': [{'id': 'call_o7uyztQLeVIoRdjcDkDJY3ni',
'type': 'function',
'function': {'name': 'get_current_weather',
'arguments': '{\n "location": "Glasgow, Scotland",\n "format": "celsius"\n}'}}]}
实际行为: 这是来自 azure/openai 客户端的完整响应(尝试了 gpt-4-turbo 和 gpt-35-turbo):
{
"id": "chatcmpl-8fr5PAthe2uTIHVjd8mcy7pOMkrx5",
"object": "chat.completion",
"model": "gpt-4",
"usage": {
"promptTokens": 172,
"completionTokens": 22,
"totalTokens": 194
},
"created": "1970-01-20T17:36:26.203Z",
"promptFilterResults": [
{
"promptIndex": 0,
"contentFilterResults": {}
}
],
"choices": [
{
"index": 0,
"finishReason": "tool_calls",
"contentFilterResult": {
"error": {
"code": "content_filter_error",
"message": "The contents are not filtered"
}
},
"message": {
"role": "assistant",
"toolCalls": []
},
"contentFilterResults": {}
}
]
}
@azure/openai 有问题的版本:1.0.0-beta.10 和 1.0.0-alpha.20240104.1
这是 OpenAI 服务的问题,而不是 Nodejs OpenAI SDK 的问题。 我查了一下,REST接口也有同样的问题。这是最近的一个变化,我对 2-3 周前的工作有积极的回忆。
有人已经向 Azure 团队报告了此问题:https://github.com/Azure/azure-sdk-for-js/issues/28343
更新: 该问题现已修复,该问题仅与少数服务区域有关。