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

uttx8gqw  于 2023-10-24  发布在  其他
关注(0)|答案(4)|浏览(300)

当我使用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结果中提取响应时,我得到了很难阅读的文本版本,类似于这样:

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

iq3niunx

iq3niunx1#

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

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

643ylb082#

问题出在我这边的前端,openAI API返回了正确的响应,而我用错误的空格CSS设置呈现了结果

lx0bsm1f

lx0bsm1f3#

更新

所有Edits API端点都已弃用。

建议更换:

  • 使用gpt-4代替text-davinci-edit-001code-davinci-edit-001
  • 使用/v1/chat/completions代替/v1/edits

选项1: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 API端点获得的补全(即编写Python代码)。

31moq8wy

31moq8wy4#

这就是white-space: pre-line;

相关问题