OpenAI API 要么不回答问题,要么我找不到给出响应的位置

问题描述 投票:0回答:1

问题总结

我正在尝试使用 OpenAI API 使用 Google Colab 向 chatgtp 3.5 Turbo 发出批量请求。它似乎工作正常但它只返回提示。它永远不会回答 1000 max_new_token 限额的问题。 我正在按照 https://platform.openai.com/docs/guides/batch/getting-started

上的说明进行操作

目标

让 Chatgtp 评估另一个 AI 生成的响应。

图书馆和数据


    chatgtp_context = """Please act as an impartial...```
    prompt = '\n # Query:\nwhy are elementary particles structureless?\n # Answer:\n',
'response': 'Hello! Elementary particles are...If you have any other questions, please let me know!'},



    import openai

    import os

    from google.colab import userdata

    OPEN_API_KEY =os.environ['OPENAI_API_KEY'] = userdata.get('OPENAI_API_KEY')

    from google.colab import files
    uploaded = files.upload()

    Llama_2_7b_output_response = Llama_2_7b_700_output_response.Llama_2_7b_output_response

API格式


    openai_queries = {
        "custom_id": "request-1",
        "method": "POST",
        "url": "/v1/chat/completions",
        "body": {
            "model": "gpt-3.5-turbo-0125",
            "messages": [
                {"role": "system", "content": chatgtp_context},
                {"role": "user", "content": Llama_2_7b_output_response}
            ],
            "max_new_tokens": 1000
        }
    }

** 请注意,“消息”是结构为“提示”示例的字典列表。

API 要求数据为 JSONL 类型文件


    with open('batch.jsonl', 'w') as jsonl_file:
      jsonl_file.write(json.dumps(openai_queries))

    from openai import OpenAI
    client = OpenAI()
    batch_input_file = client.files.create(
      file=open("batch.jsonl", "rb"),
      purpose="batch"
    )


    batch_input_file_id = batch_input_file.id

创建请求


    client.batches.create(
        input_file_id=batch_input_file_id,
        endpoint="/v1/chat/completions",
        completion_window="24h",
        metadata={
          "description": "nightly eval job"
        }
    )

获取回复


    file_response = client.files.content(batch_input_file_id)
    print(file_response.text)


我尝试查阅OPENAI的批处理手册并询问ChatGTP。查遍了互联网也没有找到答案。

据我所知,我是根据书本进行的,将调用格式化为字典列表,将其更改为 .jsonl 文件(.jsonl 文件在每一新行上都有一个字典。)

openai-api
1个回答
0
投票

哦哇。因此文档说,当您尝试检索输出时,您可以编码:

from openai import OpenAI client = OpenAI() file_response = client.files.content("file-xyz") print(file_response.text)

但是,file-xyz 不是原始 ID。在批处理完成之前,此 id 不存在。完成后,您可以在

from openai import OpenAI client = OpenAI() file_response = client.files.content("file-abc") print(file_response.text)
的输出中找到它,其中 file-abc 是原始 id。

© www.soinside.com 2019 - 2024. All rights reserved.