【问题标题】:How to keep the format of OpenAI API response?如何保持 GPT-3 API 响应的格式?
【发布时间】:2023-01-11 23:08:03
【问题描述】:

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

【问题讨论】:

    标签: gpt-3


    【解决方案1】:

    选项一:Edits endpoint

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

    测试.py

    import openai
    
    openai.api_key = "<OPENAI_API_KEY>"
    
    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 代码)。

    【讨论】:

      猜你喜欢
      • 2023-02-25
      • 2021-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      • 1970-01-01
      • 2022-12-10
      相关资源
      最近更新 更多