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

使用@azure/openai@2.0.0-beta.2调用chat.completions.create时data_sources参数不识别

解决方法
  • 停止混用@azure/openai和openai包:Azure OpenAI的专属参数(如data_sources)仅在@azure/openai包的类型定义中存在,同时引入openai官方包会导致类型冲突,直接移除openai@4.62.1依赖,仅保留@azure/openai包。
  • 使用Azure专属的类型定义:替换通用的ChatCompletionCreateParamsBase为@azure/openai包中的AzureChatCompletionCreateParams类型,该类型包含data_sources字段的定义。示例代码:
    import { AzureOpenAI } from "@azure/openai";
    import type { AzureChatCompletionCreateParams } from "@azure/openai/types";
    
    const client = new AzureOpenAI({
      apiKey: "YOUR_API_KEY",
      endpoint: "YOUR_AZURE_ENDPOINT",
      apiVersion: "2024-06-01" // 确保使用支持data_sources的API版本
    });
    
    const params: AzureChatCompletionCreateParams = {
      model: "YOUR_DEPLOYMENT_NAME",
      messages: [{ role: "user", content: "你的问题" }],
      data_sources: [
        {
          type: "azure_search",
          parameters: {
            endpoint: "YOUR_SEARCH_ENDPOINT",
            index_name: "YOUR_SEARCH_INDEX",
            api_key: "YOUR_SEARCH_KEY"
          }
        }
      ]
    };
    
    const response = await client.chat.completions.create(params);
    
  • 确保API版本正确:data_sources参数需要Azure OpenAI API版本2024-06-01或更高,在初始化AzureOpenAI客户端时指定正确的apiVersion。
  • 升级@azure/openai到最新beta版本:当前使用的2.0.0-beta.2可能存在类型定义不完善的问题,执行npm install @azure/openai@latest安装最新的beta版本,确保类型定义同步。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 06:22:03