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

Azure OpenAI GPT-4o-mini批量调用含Azure Search数据源返回空响应排查

问题排查:Azure OpenAI批量任务添加data_sources后返回空响应

问题背景

在美东区域使用Azure OpenAI批量任务,结合Azure Search索引实现检索增强生成(RAG)。使用GPT-4o-mini模型时,常规REST API调用带Azure Search数据源能正常返回结果,但批量功能中,不带data_sources标签可以得到正常响应,添加后始终返回空响应。

request.jsonl内容

{"custom_id":"task-0","method":"POST","url":"/chat/completions","body":{"model":"gpt-4o-mini-batch","messages":[{"role":"system","content":"You are an AI assistant that answers questions based only on the provided documents."},{"role":"user","content":"Tell me the names of sisters of Diana"}],"top_p":1,"frequency_penalty":0,"max_tokens":1024,"presence_penalty":0,"semantic_configuration":{"name":"my-semantic-config"},"temperature":0,"data_sources":[{"type":"azure_search","parameters":{"endpoint":"https://XXXXXXXXXXXXX.search.windows.net","scope":{"in_scope":true},"index_name":"XXXXXXXXXXXX","key":"XXXXXXXXXXXXXXX","role_information":"You are an AI assistant that helps people find information."}}]}}

Python代码

import os
from openai import AzureOpenAI
import dotenv
dotenv.load_dotenv()
    
client = AzureOpenAI(
    api_key=os.getenv("AZURE_OPENAI_KEY"),  
    api_version="2024-07-01-preview",
    azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
    )

currentDirectory = os.getcwd()
file = client.files.create(
  file=open(currentDirectory +"/resources/requestJSON.jsonl", "rb"), 
  purpose="batch"
)

print(file.model_dump_json(indent=2))
file_id = file.id

import time
import datetime

status = "pending"
while status != "processed":
    time.sleep(5)
    file_response = client.files.retrieve(file_id)
    
    status = file_response.status
    print(f"{datetime.datetime.now()} File Id: {file_id}, Status: {status}")

batch_response = client.batches.create(
    input_file_id=file_id,
    endpoint="/chat/completions",
    completion_window="24h",
)


batch_id = batch_response.id
print("BatchId-->", batch_id)
print(batch_response.model_dump_json(indent=2))

status = "validating"
while status not in ("completed", "failed", "canceled"):
    time.sleep(60)
    batch_response = client.batches.retrieve(batch_id)
    status = batch_response.status
    print(f"{datetime.datetime.now()} Batch Id: {batch_id},  Status: {status}")

import json

if status == "completed":
    file_response = client.files.content(batch_response.output_file_id)
    raw_responses = file_response.text.strip().split('\n')  

    for raw_response in raw_responses:  
        json_response = json.loads(raw_response)  
        formatted_json = json.dumps(json_response, indent=2)  
        print(formatted_json)  
elif status == "failed":
    print(f"{datetime.datetime.now()} Batch Id: {batch_id},  Status: {status}")

补充信息

  • 批量任务响应显示状态为completed,但请求计数中failed=1,且无错误提示信息
  • Azure Search索引包含嵌入向量

排查建议

  • 检查API版本兼容性:当前使用2024-07-01-preview版本,确认该版本是否支持批量任务携带data_sources参数。尝试切换到稳定版(如2024-02-01)或更新预览版测试。
  • 核对参数格式一致性:对比常规REST API的请求参数,确认批量请求中data_sources的结构是否完全匹配。注意移除重复配置,比如role_information在系统消息中已定义,可尝试删除data_sources内的该参数。
  • 验证索引访问权限:确认Azure OpenAI服务的托管标识或API密钥是否能正常访问Azure Search索引。查看Search索引的访问日志,确认批量任务是否发起过检索请求。
  • 获取详细错误日志:通过Azure OpenAI门户的批量任务详情页查看错误日志,或调用client.batches.list_errors(batch_id)接口获取具体失败原因。
  • 简化请求测试:暂时移除semantic_configuration等非核心参数,只保留data_sources和查询内容,测试是否能正常返回结果,逐步定位参数冲突问题。
  • 确认模型名称准确性:检查批量请求中的模型名称gpt-4o-mini-batch是否与Azure OpenAI部署的模型名称完全一致,避免名称不匹配导致的问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 05:26:19