OpenAI函数调用返回不完整arguments对象问题求助
OpenAI函数调用返回不完整arguments问题排查
问题现象
使用OpenAI函数调用功能时,返回响应不可靠,无法获取完整的arguments对象,始终只能拿到"{"。
函数Schema定义
export const getCoinPrice: ChatCompletionFunctions = { name: "get_coin_price", description: "Get the current price for any cryptocurrency", parameters: { type: "object", properties: { coin_symbol: { type: "string", description: "The symbol of the asset to get the price for. Eg: BTC", }, }, required: ["coin_symbol"], }, };
请求代码示例
const chatRequest: CreateChatCompletionRequest = { model: "gpt-3.5-turbo-0613", temperature: 0.5, n: 1, stop: "\n", messages: messages, function_call: "auto", functions: functions, }; const response = await this.openai.createChatCompletion(chatRequest);
异常返回内容
{"role":"user","content":"what is the current price of bitcoin"},{"role":"assistant","content":"","function_call":{"name":"get_coin_price","arguments":"{"}
解决方案建议
- 移除
stop: "\n"参数:该参数会强制模型遇到换行符就停止生成,而函数调用的arguments通常是多行JSON结构,直接被截断,这是当前问题的核心原因。 - 验证
messages数组格式:确保对话历史符合OpenAI要求,没有包含干扰模型生成逻辑的异常内容。 - 调整
temperature参数:可尝试将温度调高至0.7(或使用默认值),过低的温度可能限制模型的完整生成逻辑(优先级低于移除stop参数)。 - 确认模型版本有效性:虽然
gpt-3.5-turbo-0613支持函数调用,若存在缓存或版本歧义,可尝试明确指定完整版本号。
内容的提问来源于stack exchange,提问作者CyberPunkMetalHead
相关产品推荐
相关产品推荐

