Azure Chatbot Demo run local fail“InternalServerError:无法获取资源信息”

nzkunb0c  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(107)

我目前正在开发Azure OpenAI+认知搜索聊天机器人演示。当我尝试在本地运行演示时,我在使用openAI API时一直收到这个错误消息:
错误:无法获取资源信息。{“error”:{“code”:“InternalServerError”,“message”:“无法获取资源信息。"}} 500?“错误”:'code':'InternalServerError',' message':'无法获取资源信息。'}}'内容长度':'89',' Content-Type ':'application/json','x-ms-client-request-id':'Not-Set','apim-request-id':'edbe2b70-ae2d-44d5-b786- 286e18f72e44','Strict-Transport-Security':'max-age=31536000; includeSubDomains; preload','x-content-type-options':'nosniff',' Date ':'Tue,01 Aug 2023 08:00:55 GMT'}
我已经检查了.env并打印出所有参数,所有参数都是正确的。它也可以在Azure的应用服务上运行。只有当我尝试在本地运行时才出现问题。

ddhy6vgd

ddhy6vgd1#

错误:无法获取资源信息。{“error”:{“code”:“InternalServerError”,“message”:“无法获取资源信息。"}} 500?“错误”:'code':'InternalServerError',' message':'无法获取资源信息。'}}
以上**Internalservererror**在open-ai中由于地域问题出现,可能API key和API端点不正确。
我在本地尝试了相同的代码来运行Azure OpenAI+认知搜索聊天机器人演示。

验证码:

import os
import requests
import json
import openai
from azure.search.documents import SearchClient
from azure.core.credentials import AzureKeyCredential

# Set up OpenAI API
openai.api_key = "xxxxx"
openai.api_base = "https://xxxxx.openai.azure.com/"
openai.api_type = 'azure'
openai.api_version = '2023-05-15'

# Set up Azure Cognitive Search
search_service_name = "xxxx"
index_name = "xxxxx"
admin_key = "xxxxxxx"
credential = AzureKeyCredential(admin_key)
client = SearchClient(endpoint=f"https://{search_service_name}.search.windows.net/", index_name=index_name, credential=credential)

def search_index(query):
    search_results = client.search(search_text=query)
    return list(search_results)

def generate_response(prompt):
    response = openai.Completion.create(
        engine="deployment1", #text-davinci-002
        prompt=prompt,
        max_tokens=1024,
        n=1,
        stop=None,
        temperature=0.5,
    )
    return response.choices[0]['text'].replace('\n', '').replace(' .', '.').strip()

def handle_input(input_text):
    search_results = search_index(input_text)
    if len(search_results) > 0:
        return search_results[0]['content']
    else:
        prompt = f"Q: {input_text}\nA:"
        response = generate_response(prompt)
        return response

def run_chatbot():
    print("Welcome to the Azure OpenAI+Cognitive Search Chatbot Demo!")
    while True:
        # Get user input
        user_input = input("You: ")
        # Handle user input and generate response
        response = handle_input(user_input)
        # Print response
        print("Chatbot:", response)

run_chatbot()

字符串

输出:

Welcome to the Azure OpenAI+Cognitive Search Chatbot Demo!
You: dhoni
Chatbot: Dhoni is a former Indian cricketer and the current captain of the Indian national cricket team. He is considered one of the greatest cricket captains of all time.


x1c 0d1x的数据

参考号:

相关问题