gpt4 book ai didi

python - 如何获取请求响应中的字符串内容?

转载 作者:行者123 更新时间:2023-12-02 05:47:00 24 4
gpt4 key购买 nike

我正在编写一个基于 GPT-2 的网络应用程序,但它并不好,所以我决定切换到官方 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"
}

但是我只想打印文本,那么如何打印响应列表中的“文本”值。提前谢谢你,祝你有美好的一天。

最佳答案

使用字典键索引,列表索引索引

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

关于python - 如何获取请求响应中的字符串内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68038662/

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