chatgpt-web-dev / chatgpt-web

A third-party ChatGPT Web UI page built with Express and Vue3, through the official OpenAI completion API. / 用 Express 和 Vue3 搭建的第三方 ChatGPT 前端页面, 基于 OpenAI 官方 completion API.
https://chatgpt-web.dev
MIT License
1.54k stars 437 forks source link

【错误】连续对话错误 #532

Closed Yang2635 closed 1 month ago

Yang2635 commented 1 month ago

使用三方的chat2api服务,配置如下图: image

在本项目网站使用Chat2API进行连续对话时会出现错误(不影响单次对话),错误如图: image

在NextChat项目网站上进行同样的配置,可正常连续对话,如图: image

根据docker容器日志内容输出,如下:

sendMessage (54 tokens) {
  max_tokens: 1024,
  model: 'gpt-3.5-turbo',
  temperature: 0.8,
  top_p: 1,
  presence_penalty: 1,
  messages: [
    {
      role: 'system',
      content: "You are a large language model. Follow the user's instructions carefully. Please respond in the Chinese language. Use native Markdown for responsiveness.\n" +
        'Latex inline: $x^2$\n' +
        'Latex block: $$e=mc^2$$.'
    },
    { role: 'user', content: '你好' }
  ],
  stream: true
}
sendMessage (86 tokens) {
  max_tokens: 1024,
  model: 'gpt-3.5-turbo',
  temperature: 0.8,
  top_p: 1,
  presence_penalty: 1,
  messages: [
    {
      role: 'system',
      content: "You are a large language model. Follow the user's instructions carefully. Please respond in the Chinese language. Use native Markdown for responsiveness.\n" +
        'Latex inline: $x^2$\n' +
        'Latex block: $$e=mc^2$$.'
    },
    { role: 'user', content: [ { type: 'text', text: '你好' } ] },
    { role: 'assistant', content: '你好!有什么可以帮助你的吗?' },
    { role: 'user', content: '自我介绍一下' }
  ],
  stream: true
}
ChatGPTError: ChatGPT error 400: {"error":{"message":"invalid paramters","type":"invalid_request_error","param":null,"code":null}}
    at fetchSSE (file:///app/node_modules/.pnpm/@chatgptweb+chatgpt-api@5.3.0/node_modules/@chatgptweb/chatgpt-api/build/index.js:56:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  statusCode: 400,
  statusText: 'Bad Request',
  [cause]: Response {
    status: 400,
    statusText: 'Bad Request',
    headers: Headers {
      date: 'Sat, 11 May 2024 07:09:25 GMT',
      'content-type': 'text/plain; charset=utf-8',
      'content-length': '97',
      connection: 'keep-alive',
      'x-server': 'oaifree/0.0.2',
      'cf-cache-status': 'DYNAMIC',
      'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v4?s=fCp05aee6fpV9sSkA4RSfGT%2BQxXFKaOQprcOhnv5mGdFnjrkIWSMjNXbUnCBuw8OJkQj4aOSm0%2BopH1U9TYD8t%2FFH7DoJQLvwd0VrgtUL2CUkXjJcNPDX%2BMbp3R8Gyz%2FWRA%3D"}],"group":"cf-nel","max_age":604800}',
      nel: '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}',
      'strict-transport-security': 'max-age=15552000; includeSubDomains; preload',
      'expect-ct': 'max-age=86400, enforce',
      'referrer-policy': 'same-origin',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'SAMEORIGIN',
      'x-xss-protection': '1; mode=block',
      server: 'cloudflare',
      'cf-ray': '882057e56f83941e-LHR',
      'alt-svc': 'h3=":443"; ma=86400'
    },
    body: ReadableStream { locked: true, state: 'closed', supportsBYOB: true },
    bodyUsed: true,
    ok: false,
    redirected: false,
    type: 'basic',
    url: 'https://api.oaifree.com/v1/chat/completions'
  }
}

初步判断定位可能是在该处的问题导致:

……
    { role: 'user', content: [ { type: 'text', text: '你好' } ] }, <---此处
    { role: 'assistant', content: '你好!有什么可以帮助你的吗?' },
    { role: 'user', content: '自我介绍一下' }
……

上述content重新处理后,可正常连续对话: image