OpenAI gpt-3.5-turbo:请求失败,状态代码 400
P粉546138344
P粉546138344 2023-09-01 12:17:58
0
1
491
<p>node.js 中的这个方法不再起作用了吗?因为当时它工作正常,但现在它不再工作了,而且此代码也基于他们的官方文档,即 https://platform.openai.com/docs/api-reference/completions/create</ p> <p><strong>我的服务器端代码:</strong></p> <pre class="brush:js;toolbar:false;"> import { Configuration, OpenAIApi } from 'openai'; //.... const configuration = new Configuration({ apiKey: API_KEY, }); //.... const openai = new OpenAIApi(configuration); //.... const response = await openai.createChatCompletion({ model: "gpt-3.5-turbo", messages: [ { role: "system", content: `You are a helpful assistant.` }, ...prompt ], temperature: 0.2, max_tokens: 1500, top_p: 1, frequency_penalty: 0, presence_penalty: 0, }); //.... res.status(200).send({ bot: response.data.choices[0].message.content }); //.... </pre> <p><strong>我尝试发送的数据:</strong></p> <pre class="brush:json;toolbar:false;">{ "prompt": [ { "role": "bot", "content": "Something went wrong." }, { "role": "user", "content": "What is wrong?" } ] } </pre> <p><strong>我遇到了这种错误:</strong> | 消息提示的输出位于终端中,以防您想检查我是否发送了正确的消息提示。</p> <p>我还尝试添加组织 ID,但仍然不起作用,也尝试将其从 v3.2.1 更新到 v3.3.0,但根本不起作用。我的账户里还有余额。</p>
P粉546138344
P粉546138344

全部回复(1)
P粉267791326

问题已解决,我发送了错误的角色而不是机器人,它应该是助理。所以这种格式将使一切恢复正常:

{
  "prompt": [
    {
      "role": "assistant",
      "content": "Something went wrong."
    },
    {
      "role": "user",
      "content": "What is wrong?"
    }
  ]
}

基于https://platform.openai.com/docs/api -reference/chat/create 只有 4 个角色:systemuserassistantfunction代码>

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!