作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想获取此数据结构中通过 GPT3 OpenAI 输出的文本。我正在使用 Python。当我打印我得到的对象时:
<OpenAIObject text_completion id=cmpl-6F7ScZDu2UKKJGPXTiTPNKgfrikZ at 0x7f7648cacef0> JSON: {
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"text": "\nWhat was Malcolm X's original name?\nMalcolm X's original name was Malcolm Little.\n\nWhere was Malcolm X born?\nMalcolm X was born in Omaha, Nebraska.\n\nWhat was the profession of Malcolm X's father?\nMalcolm X's father was a Baptist minister.\n\nWhat did Malcolm X do after he stopped attending school?\nMalcolm X became involved in petty criminal activities."
}
],
"created": 1669061618,
"id": "cmpl-6F7ScZDu2gJJHKZSPXTiTPNKgfrikZ",
"model": "text-davinci-002",
"object": "text_completion",
"usage": {
"completion_tokens": 86,
"prompt_tokens": 1200,
"total_tokens": 1286
}
}
我如何获得它的“文本”组件?例如,如果调用此对象:qa ...我可以输出
qa['choices']
我得到了与上面相同的项目...但是向其中添加 .text
或 ['text'] 并不能做到这一点。并得到一个错误
但不确定如何隔离“文本”我已阅读文档,但找不到这个... https://beta.openai.com/docs/api-reference/files/delete?lang=python谢谢
最佳答案
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 - 如何在 python 中获取 OpenAIobject 中的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74524530/
我是一名优秀的程序员,十分优秀!