我正在编写一个基于GPT-2的was应用程序,但是它不是很好,所以我决定切换到正式的OpenAI GPT-3。所以我提出这个要求:
response = openai.Completion.create(
engine="davinci",
prompt="Hello",
temperature=0.7,
max_tokens=64,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)当我打印回复时,我得到的是:
{
"choices": [
{
"finish_reason": "length",
"index": 0,
"logprobs": null,
"text": ", everyone, and welcome to the first installment of the new opening"
}
],
"created": 1624033807,
"id": "cmpl-3CBfb8yZAFEUIVXfZO90m77dgd9V4",
"model": "davinci:2020-05-03",
"object": "text_completion"
}但是我只想打印文本,那么如何在响应列表中打印" text“值呢?先谢谢你,祝你今天愉快。
发布于 2021-06-18 16:36:38
按键使用dict索引,按索引使用列表索引
x = {"choices": [{"finish_reason": "length",
"text": ", everyone, and welcome to the first installment of the new opening"}], }
text = x['choices'][0]['text']
print(text) # , everyone, and welcome to the first installment of the new opening发布于 2022-06-05 18:00:00
您可以尝试打印(响应“选择”“文本”)
希望这能有所帮助。
发布于 2022-10-11 03:42:50
我认为GPT-3响应结构已经更改,作为参考,响应对象如下:
const response = await openai.createCompletion({
model: "text-davinci-002",
prompt: "Say this is a test",
temperature: 0,
max_tokens: 6,
});
// the response looks like the following
{
status: 200,
statusText: 'OK',
headers: {
},
config: {
},
request: <ref *1> ClientRequest {
},
data: {
id: 'cmpl-5zzyzqvh4Hmi5yyNL2LMI9ADkLBU0',
object: 'text_completion',
created: 1665457953,
model: 'text-davinci-002',
choices: [ [Object] ],
usage: { prompt_tokens: 5, completion_tokens: 6, total_tokens: 11 }
}
}
// choices can be accessed like this
var { choices } = { ...response.data }https://stackoverflow.com/questions/68038662
复制相似问题