Error when attempting to add data source to Azure OpenAI api

题意:尝试向 Azure OpenAI API 添加数据源时出现错误

问题背景:

My code is working for a call to Azure OpenAI when I don't have a datasource added. However, when I do add my datasource with the following parameters I get an error:

当我没有添加数据源时,我的代码在调用 Azure OpenAI 时可以正常工作。然而,当我使用以下参数添加数据源时,出现了错误:

cs 复制代码
response = client.chat.completions.create(
    messages = [
        {
            "role": "system",
            "content": "when the user provides a project name as input you should do the steps mentioned below: Step 1: Get the project band of the project from the file."
        },
        {
            "role": "user",
            "content": 'Project Name: "Test project" '
        }
    ],
    model = "GPT-3.5 Turbo",
    seed = 42,
    temperature = 0,
    max_tokens = 800,
    extra_body = {
        "dataSources": [
            {
                "type": "AzureCognitiveSearch",
                "parameters": {
                    "endpoint": os.environ["SEARCH_ENDPOINT"],
                    "key": os.environ["SEARCH_KEY"],
                    "indexName": "test-index"
                }
            }
        ]

Gives error: 错误信息:

cs 复制代码
Exception has occurred: BadRequestError
Error code: 400 - {'error': {'message': 'Unrecognized request argument supplied: dataSources', 'type': 'invalid_request_error', 'param': None, 'code': None}}
httpx.HTTPStatusError: Client error '400 model_error' for url 'https://openai-ngap-genai-poc.openai.azure.com//openai/deployments/NTAPOC/chat/completions?api-version=2023-09-01-preview'
For more information check: https://httpstatuses.com/400

During handling of the above exception, another exception occurred:

  File "C:\Users\choran\OneDrive - Open Sky Data Systems\Documents\NTA\NTA Chatbot code\Attempting to add datasource.py", line 13, in <module>
    response = client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
openai.BadRequestError: Error code: 400 - {'error': {'message': 'Unrecognized request argument supplied: dataSources', 'type': 'invalid_request_error', 'param': None, 'code': None}}

Verified that datasource details were correct.

Full code here

问题解决:

In my environment, when I tried the same code, I got the same error:

在我的环境中,当我尝试相同的代码时,也遇到了相同的错误:

Error**:**

openai.BadRequestError: Error code: 400 - {'error': {'message':'Unrecognized request argument supplied: dataSources', 'type': 'invalid_request_error', 'param': None, 'code': None}}

You can use this MS-DOCS to create your own data with chat completion.

你可以使用这个 [MS-DOCS](https://docs.microsoft.com) 来创建自己的数据,并进行聊天补全。

You can use the code below to create chat completion with data source and openai version 1.9.0.

你可以使用下面的代码,在数据源和 OpenAI 版本 1.9.0 下创建聊天补全。

Code:

cs 复制代码
import os
from openai import AzureOpenAI

endpoint=os.environ["AZURE_ENDPOINT"]
deployment="gpt-35-turbo"
apikey=os.environ["API_KEY"]
client = AzureOpenAI(
    base_url=f"{endpoint}/openai/deployments/{deployment}/extensions", 
    api_key=apikey, 
    api_version="2023-09-01-preview")

for i in range(3):
    print (f'Answer Version {i + 1}\n---')

completion = client.chat.completions.create(
    model = deployment,
    messages = [
        {
            "role": "system",
            "content": "When the user provides a project name as input, you should do the steps mentioned below: Step 1: Get the project band of the project from the file."
        },
        {
            "role": "user",
            "content": 'Where do I go for Azure OpenAI customer support?" '
        }
    ],
    seed = 42,
    temperature = 0,
    max_tokens = 800,
    extra_body = {
        "dataSources": [
            {
                "type": "AzureCognitiveSearch",
                "parameters": {
                    "endpoint": os.environ["SEARCH_ENDPOINT"],
                     "key": os.environ["SEARCH_KEY"],
                     "indexName": "test-index"
                    }
             }
        ]
    }
)
print (completion.choices[0].message.content) 

print("---\n")

Output:

cs 复制代码
Answer Version 1
---
Answer Version 2
---
Answer Version 3
---
You can check the Cognitive Services support options guide for help with Azure OpenAI [doc1].
相关推荐
孤独且没人爱的纸鹤40 分钟前
【深度学习】:从人工神经网络的基础原理到循环神经网络的先进技术,跨越智能算法的关键发展阶段及其未来趋势,探索技术进步与应用挑战
人工智能·python·深度学习·机器学习·ai
数字化营销工兵1 小时前
大语言模型(LLM)安全:十大风险、影响和防御措施
llm·大语言模型·数据安全·隐私保护
gz7seven10 小时前
BLIP-2模型的详解与思考
大模型·llm·多模态·blip·多模态大模型·blip-2·q-former
老艾的AI世界13 小时前
AI翻唱神器,一键用你喜欢的歌手翻唱他人的曲目(附下载链接)
人工智能·深度学习·神经网络·机器学习·ai·ai翻唱·ai唱歌·ai歌曲
不爱说话郭德纲15 小时前
探索LLM前沿,共话科技未来
人工智能·算法·llm
我爱学Python!21 小时前
解决复杂查询难题:如何通过 Self-querying Prompting 提高 RAG 系统效率?
人工智能·程序人生·自然语言处理·大模型·llm·大语言模型·rag
飞起来fly呀1 天前
AI驱动电商新未来:提升销售效率与用户体验的创新实践
人工智能·ai
Jing_jing_X1 天前
心情追忆-首页“毒“鸡汤AI自动化
java·前端·后端·ai·产品经理·流量运营
刘悦的技术博客2 天前
MagicQuill,AI动态图像元素修改,AI绘图,需要40G的本地硬盘空间,12G显存可玩,Win11本地部署
ai·aigc·python3.11
任某某01162 天前
第四期书生大模型实战营 - 基础岛闯关作业3 - 浦语提示词工程实践
llm