ChatGPT-3 如何保持OpenAI API响应的格式?

icnyk63a  于 2023-03-03  发布在  其他
关注(0)|答案(1)|浏览(340)

当我使用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结果的格式,以便以更整洁、更可读的方式显示它们?

cvxl0en2

cvxl0en21#

选项1:Edits endpoint

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

    • 测试. 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)

选项2:加工

自己处理从Completions endpoint获得的完成(例如,编写Python代码)。

相关问题