如何在使用OpenAI GPT-3 API时保持OpenAI API响应的格式?

7vux5j2d  于 2023-04-22  发布在  其他
关注(0)|答案(2)|浏览(257)

当我使用GPT3的playground时,我经常得到带有编号列表和段落格式的结果,如下所示:

Here's what the above class is doing:

1. It creates a directory for the log file if it doesn't exist.
2. It checks that the log file is newline-terminated.
3. It writes a newline-terminated JSON object to the log file.
4. It reads the log file and returns a dictionary with the following

- list 1
- list 2
- list 3
- list 4

然而,当我直接使用他们的API并从json result中提取响应时,我得到的是非常难以阅读的填鸭式文本版本,如下所示:

Here's what the above class is doing:1. It creates a directory for the log file if it doesn't exist.2. It checks that the log file is newline-terminated.3. It writes a newline-terminated JSON object to the log file.4. It reads the log file and returns a dictionary with the following-list 1-list 2-list 3- list4

我的问题是,人们如何保持GPT结果的格式,使它们以更整洁,更可读的方式显示?

xqkwcwgp

xqkwcwgp1#

选项一:Edits endpoint

如果运行test.py,OpenAI API将返回以下完成:

test.py

import openai

openai.api_key = 'sk-xxxxxxxxxxxxxxxxxxxx'

response = openai.Edit.create(
  model = 'text-davinci-edit-001',
  input = 'I have three items:1. First item.2. Second item.3. Third item.',
  instruction = 'Make numbered list'
)

content = response['choices'][0]['text']

print(content)

选项二:加工

自己处理从Completions endpoint得到的补全(即编写Python代码)。

tzcvj98z

tzcvj98z2#

最好的答案是提供一个你想要的输出的例子。例子中的数据并不重要,只要显示你想要的结构就行了。

Example output:
Here's what the above class is doing:
1. It blah.
2. It blah.

相关问题