gpt4 book ai didi

python - OpenGPT API 输出中的 `index`

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

下面是代码

import os
import openai


openai.api_key = "..."


response = openai.Completion.create(
model="text-davinci-003",
prompt="I am happy!",
temperature=0, #creativity
max_tokens=10,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.0,
suffix='I am even more happy!'
)

print(response)

输出如下

{
"choices": [
{
"finish_reason": "length",
"index": 0,
"logprobs": null,
"text": "\n\nI am happy because I am surrounded by"
}
],
"created": 1674640360,
"id": "cmpl-6cWkK124234ho8C2134afasdasdnwDKLUMP",
"model": "text-davinci-003",
"object": "text_completion",
"usage": {
"completion_tokens": 10,
"prompt_tokens": 10,
"total_tokens": 20
}
}

下面输出中的index代表什么?

最佳答案

索引是指回复的提示的索引。

由于 prompt 可以是字符串或数组,documentation将其称为:

prompt string or array

The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, or array of token arrays.


例如,考虑调用 /completions带有 2 个提示的端点:

{
"model": "text-davinci-003",
"prompt": [
"How should I", // [ 0 ]
"Should I" // [ 1 ]
],
"max_tokens": 7,
"temperature": 0
}

OpenAI 将回答这两个提示,index 将引用 prompt 中原始索引的回复:

{
"choices": [
{
"text": " go about doing this?\n\n",
"index": 0, // Answers prompt[0]
"logprobs": null,
"finish_reason": "length"
},
{
"text": " use a VPN on my iPhone?",
"index": 1, // Answers prompt[1]
"logprobs": null,
"finish_reason": "length"
}
]
}

在您的示例中,只有 1 个 prompt,因此 API 只会在 choices 数组中发送 1 个对象,因此 index将始终为 0

关于python - OpenGPT API 输出中的 `index`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75232276/

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