当前位置: 首页 > article >正文

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 时可以正常工作。然而,当我使用以下参数添加数据源时,出现了错误:

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:        错误信息:

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:

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:

Answer Version 1
---
Answer Version 2
---
Answer Version 3
---
You can check the Cognitive Services support options guide for help with Azure OpenAI [doc1].


http://www.kler.cn/news/290463.html

相关文章:

  • uniapp css样式盒子上面的箭头样式
  • ElasticSearch学习笔记(四)分页、高亮、RestClient查询文档
  • 20240904日报
  • C#如何查看/写入日志到Windows事件查看器
  • c++学习笔记(5)
  • .gitignore 修改问题
  • 力扣151.反转字符串中的单词
  • 输电线路分布式故障诊断系统:分布式智慧网络的构建
  • c#笔记5 详解事件的内置类型EventHandler、windows事件在winform中的运用
  • 【IEEE出版 | 往届会后3个月EI检索】第三届IEEE云计算、大数据应用与软件工程国际学术会议 (IEEE-CBASE 2024,10月18-20)
  • 6 - Shell编程之sed与awk编辑器
  • 高级java每日一道面试题-2024年8月28日-框架篇[Spring篇]-你对Spring的事务管理了解多少?
  • Windows bat脚本学习七(从hex文件中获取bin大小)
  • centos 局域网 内部 时间同步 chrony
  • PHP7 的内核结构
  • 河南省第三届职业技能大赛 网站技术(世赛选拔)项目任务书
  • Go 项目中的 GOPROXY 设置
  • 三极管的检测方法与经验
  • Transiting from CUDA to HIP(三)
  • 刘润《关键跃升》读书笔记6
  • Linux基础指令(二)详解
  • 告别PDF格式困扰,2024年PDF转换器推荐
  • 「OC」iOS事件处理流程
  • Elasticsearch之储存原理和优化
  • 部分设计模式(java语言版本)
  • 常见排序方法详解(图示+方法)
  • VBA中类的解读及应用第十五讲:让文本框在激活时改变颜色(上)
  • HarmonyOS开发实战( Beta5版)多线程能力场景化示例最佳实践
  • 虚幻地形高度图生成及测试
  • 【论文分享】MyTEE: Own the Trusted Execution Environment on Embedded Devices 23‘NDSS