gpt4 book ai didi

javascript - 如何指定 OpenAI 完成应返回的最大字数

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

如何指定 Open AI 补全应返回的字数?

例如,想象一下我问 AI 这个问题

Who is Elon Musk?

我可以使用什么参数来确保 AI 发回的结果少于或等于 300 个单词。

我在想 max_tokens 参数是为了那个,但似乎 max_tokens 是为了分解输入而不是输出。

任何想法将不胜感激。谢谢

最佳答案

您在 Playground 中查找的参数称为 Maximum length,在 API 中为 "max_tokens" . token 在提示和完成之间共享。

The number of tokens processed in a given API request depends on thelength of both your inputs and outputs. As a rough rule of thumb, 1token is approximately 4 characters or 0.75 words for English text.One limitation to keep in mind is that your text prompt and generatedcompletion combined must be no more than the model's maximum contextlength (for most models this is 2048 tokens, or about 1500 words).Check out our tokenizer tool to learn more about how text translatesto tokens.

参见 docs

请注意,此参数处理的是标记而不是单词。如果你想找到与标记相等的单词数,请使用 tokenizer .

关于javascript - 如何指定 OpenAI 完成应返回的最大字数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71888625/

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