如何指定 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 the length of both your inputs and outputs. As a rough rule of thumb, 1 token is approximately 4 characters or 0.75 words for English text. One limitation to keep in mind is that your text prompt and generated completion combined must be no more than the model's maximum context length (for most models this is 2048 tokens, or about 1500 words). Check out our tokenizer tool to learn more about how text translates to tokens.
参见 docs
请注意,此参数处理的是标记而不是单词。如果你想找到与标记相等的单词数,请使用 tokenizer .
关于javascript - 如何指定 OpenAI 完成应返回的最大字数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71888625/