对于在Python中进行的简单OpenAI API调用
response = openai.ChatCompletion.create( model="gpt-4", messages=[ {"role": "system", "content": instructions}, {"role": "user", "content": my_input} ])
我能在 response['choices'][0]['message']['content']
中获取有意义的数据
在什么情况下 response['choices']
中会有多个条目?我应该如何理解这一点?
回答:
据我所见,文档中提到,如果你将参数 n
设置为大于1,你将获得多个”choice
“。
https://platform.openai.com/docs/api-reference/chat/create
n 整数或null 可选 默认值为1
为每个输入消息生成多少个聊天完成选项。请注意,你将根据所有选项中生成的代币数量收费。为了最小化成本,请将n保持为1。
我不知道将其命名为 choices
的概念,但我可以告诉你,默认值是 1
,所以除非你更改 n
参数,否则你总是需要从 choices
中访问索引 0
。