You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:OpenAI批量API仅返回Prompt无响应问题排查

问题排查与解决方案

核心错误:获取了输入文件而非批量任务输出文件

你当前获取响应的代码调用的是批量任务的输入文件内容,自然只会看到提交的Prompt,而非模型生成的回答。正确流程是等待批量任务完成后,获取任务对应的输出文件。

修正步骤

1. 保存批量任务ID

创建批量任务时,保存任务ID以便后续查询状态:

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

2. 轮询任务状态,获取输出文件ID

批量任务需要时间处理,需等待任务完成后提取输出文件:

import time

# 轮询任务状态(可根据实际情况调整查询间隔)
while True:
    batch_status = client.batches.retrieve(batch_job_id)
    if batch_status.status == "completed":
        output_file_id = batch_status.output_file_id
        print("Batch job completed, output file ID:", output_file_id)
        break
    elif batch_status.status in ["failed", "expired"]:
        print(f"Batch job failed: {batch_status.error}")
        break
    print(f"Current status: {batch_status.status}, waiting...")
    time.sleep(60)  # 每分钟查询一次

3. 获取并输出模型生成的响应

通过输出文件ID获取批量任务的最终结果:

if output_file_id:
    file_response = client.files.content(output_file_id)
    print(file_response.text)

其他潜在问题排查

  • JSONL文件格式:确保每个请求是单独一行的JSON对象(当前单个请求无问题,若后续批量处理多个请求,需每行写入一个json.dumps()结果)。
  • 系统提示完整性:检查chatgtp_context的字符串是否完整闭合,避免因格式错误导致模型无法理解指令。
  • 输入内容有效性:确认Llama_2_7b_output_response变量确实包含需要评估的完整响应内容,无截断或格式异常。
  • 参数合法性:gpt-3.5-turbo-0125支持max_new_tokens参数,需确保总token数(Prompt+生成内容)不超过模型上限(4096)。

内容的提问来源于stack exchange,提问作者SimpleRandomJoe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 02:22:41