我的提示是 1360 个 token ,由 Playground 和 Tokenizer 验证。我不会显示提示,因为对于这个问题来说它有点太长了。


这是我使用 openai npm 包在 Nodejs 中对 openai 的请求。


const response = await openai.createCompletion({

  model: 'text-davinci-003',

  prompt,

  max_tokens: 4000,

  temperature: 0.2

})

在 Playground 上测试时,响应后我的总标记为 1374。


通过完成 API 提交我的提示时,出现以下错误:


error: {

  message: "This model's maximum context length is 4097 tokens, however you requested 5360 tokens (1360 in your prompt; 4000 for the completion). Please reduce your prompt; or completion length.",

  type: 'invalid_request_error',

  param: null,

  code: null

}

如果您能够解决这个问题,我很想听听您是如何解决的。


最佳答案


max_tokens 参数在提示和完成之间共享。来自提示和完成的 token 加起来不应超过特定 GPT-3 模型的 token 限制。


如官方所述OpenAI article :


Depending on the model used, requests can use up to 4097 tokens shared between prompt and completion. If your prompt is 4000 tokens, your completion can be 97 tokens at most.


The limit is currently a technical limitation, but there are often creative ways to solve problems within the limit, e.g. condensing your prompt, breaking the text into smaller pieces, etc.


GPT-3 models :


关于openai-api - OpenAI GPT-3 API 错误 : "This model' s maximum context length is 4097 tokens",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75396481/