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

标签 javascript node.js openai-api

如何指定 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/

相关文章:

javascript - 带有自定义 json 数据的 JsTree

node.js - Express js 中的多级路由

reactjs - 如何将来自 API 的响应保存到某个状态,以便我可以显示旧的搜索/响应?

python - 如何让Open AI API返回部分文本结果?

javascript - 如何在javascript中设置弹出文本的格式?

javascript - 为什么主要的pencilblue模块没有pencilblue.js

javascript - 全局 Jest SpyOn 函数不调用原始函数

javascript - 对从 AJAX 发送到我的 Express 服务器的请求路径感到困惑

javascript - Mongodb node driver 2.0.* with Bluebird 2.9.* promisification

openai-api - OpenAI GPT-3 API : Why do I get only partial completion? 为什么完成中断?