题意:"什么时候我可以在 OpenAI 的回复中预期到多个“选择”?"
问题背景:
For a simple OpenAI api call in python
对于一个在 python 中简单的 OpenAI API 调用
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{"role": "system", "content": instructions},
{"role": "user", "content": my_input}
])
I get meaningful data in response['choices'][0]['message']['content']
我在 response['choices'][0]['message']['content'] 中获取到有意义的数据
Under what circumstances will there be multiple entries in response['choices']
? How should I interpret this?
在什么情况下 response['choices'] 中会有多个条目?我应该如何理解这一点?
问题解决:
From what I see, the documentation says that if you set the parameter n
to more than 1 you will get more than one "choice
".
"据我所知,文档中提到,如果将参数 n 设置为大于 1,你将会获得多个 '选择'。
https://platform.openai.com/docs/api-reference/chat/create
n integer or null Optional Defaults to 1
How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.
I don't know the concept behind naming it choices
, but I can tell you that the default is 1
, so you always will have to access index 0
from choices
unless you change the n
parameter.
"我不清楚将其命名为 choices 背后的概念,但我可以告诉你,默认值是 1,所以你总是需要从 choices 中访问索引 0,除非你更改了 n 参数。"