Reputation: 1
I am currently working on the Azure OpenAI+Cognitive Search Chatbot Demo. And as I try to run the demo locally, I kept getting this error message when using openAI API:
Error: Unable to get resource information. {"error":{"code":"InternalServerError","message": "Unable to get resource information."}} 500 {'error': {'code': 'InternalServerError', 'message': 'Unable to get resource information.'}} {'Content-Length': '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'}
I have checked .env and printed out all the parameters, and all of them are correct. And it can also run on Azure's app service. The problem only occurred when I tried to run locally.
Upvotes: 0
Views: 480
Reputation: 10410
Error: Unable to get resource information. {"error":{"code":"InternalServerError","message": "Unable to get resource information."}} 500 {'error': {'code': 'InternalServerError', 'message': 'Unable to get resource information.'}}
The above Internalservererror
occurs in open-ai due to region problems and may be incorrect in the API key and API endpoint.
I tried the same code locally to run Azure OpenAI+Cognitive Search Chatbot Demo.
Code:
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()
Output:
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.
Reference:
Upvotes: 0