gpt4 book ai didi

openai-api - OpenAI GPT-3 API 错误 : "This model' s maximum context length is 4097 tokens"

转载 作者:行者123 更新时间:2023-12-02 05:46:21 26 4
gpt4 key购买 nike

我正在向完成端点发出请求。我的提示是 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 sharedbetween prompt and completion. If your prompt is 4000 tokens, yourcompletion can be 97 tokens at most.

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

GPT-3 models :

Table

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com