You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 23:27:29