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

问题描述

我正在编写一个基于 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"
}

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

解决方法

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

too big