chatgpt-web icon indicating copy to clipboard operation
chatgpt-web copied to clipboard

疑问:接口返回的数据结构和官方说的不一样?

Open 1970168137 opened this issue 1 year ago • 1 comments

源码中的代码段(service/src/chatgpt/index.ts)中的代码段如下:

const response = await api.sendMessage(message, {
  ...options,
  onProgress: (partialResponse) => {
    process?.(partialResponse)
  },
})

运行源码的返回如下: { response: { role: 'assistant', id: 'chatcmpl-79c2gjsvDXAURJKYNBgePFFP55rmO', parentMessageId: '375f64c1-9ff5-4988-8aeb-d06b4cbe4a0a', text: '你好,有什么我可以帮助你的吗?', delta: undefined, detail: { id: 'chatcmpl-79c2gjsvDXAURJKYNBgePFFP55rmO', object: 'chat.completion.chunk', created: 1682525542, model: 'gpt-3.5-turbo-0301', choices: [Array] } } }

但官方说明的返回如下: { "id":"chatcmpl-abc123", "object":"chat.completion", "created":1677858242, "model":"gpt-3.5-turbo-0301", "usage":{ "prompt_tokens":13, "completion_tokens":7, "total_tokens":20 }, "choices":[ { "message":{ "role":"assistant", "content":"\n\nThis is a test!" }, "finish_reason":"stop", "index":0 } ] }

是不是我弄错了什么了?为什么两个接口返回结构的不一样?我想得到total_tokens,应该对应源码中哪段获取呢?

1970168137 avatar Apr 27 '23 09:04 1970168137

这个是封装过的

bosstwobread avatar Apr 27 '23 10:04 bosstwobread

这个是封装过的

那有没有雷同 api.sendMessage 一样作用的,但可以获得官方标准返回的方法?

1970168137 avatar Apr 28 '23 09:04 1970168137

This issue is stale because it has been open for 10 days with no activity.

github-actions[bot] avatar May 09 '23 01:05 github-actions[bot]

This issue was closed because it has been inactive for 2 days since being marked as stale.

github-actions[bot] avatar May 12 '23 01:05 github-actions[bot]