gpt4 book ai didi

openai-api - OpenAI GPT-3 API : How to keep the format of the OpenAI API response?

转载 作者:行者123 更新时间:2023-12-02 22:45:10 27 4
gpt4 key购买 nike

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

最佳答案

选项 1:Edits endpoint

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

Python

测试.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 代码)。

关于openai-api - OpenAI GPT-3 API : How to keep the format of the OpenAI API response?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75084272/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com