azure-search-openai-demo icon indicating copy to clipboard operation
azure-search-openai-demo copied to clipboard

how can i solve Openai Error (500 Error)?

Open funny1853 opened this issue 1 year ago • 2 comments

Please provide us with the following information:

This issue is for a: (mark with an x)

- [x ] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

i am trying to re-deploy this demo locally, however, i keep having a under issue. when i run this demo through terminal, then it works very well.

Any log messages given by the failure

ERROR:root:Exception in /chat Traceback (most recent call last): File "C:\Users\funny\open_ai_demo_yg\azure-search-openai-demo\app\backend\app.py", line 121, in chat r = impl.run(request.json["history"], request.json.get("overrides") or {}) File "C:\Users\funny\open_ai_demo_yg\azure-search-openai-demo\app\backend\approaches\chatreadretrieveread.py", line 64, in run completion = openai.Completion.create( File "C:\Users\funny\open_ai_demo_yg\azure-search-openai-demo\app\backend\backend_env\lib\site-packages\openai\api_resources\completion.py", line 25, in create return super().create(*args, **kwargs) File "C:\Users\funny\open_ai_demo_yg\azure-search-openai-demo\app\backend\backend_env\lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 153, in create response, _, api_key = requestor.request( File "C:\Users\funny\open_ai_demo_yg\azure-search-openai-demo\app\backend\backend_env\lib\site-packages\openai\api_requestor.py", line 227, in request resp, got_stream = self._interpret_response(result, stream) File "C:\Users\funny\open_ai_demo_yg\azure-search-openai-demo\app\backend\backend_env\lib\site-packages\openai\api_requestor.py", line 620, in _interpret_response self._interpret_response_line( File "C:\Users\funny\open_ai_demo_yg\azure-search-openai-demo\app\backend\backend_env\lib\site-packages\openai\api_requestor.py", line 680, in _interpret_response_line raise self.handle_error_response( openai.error.APIError: 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': '615f2b8c-7ad6-4bd5-ab42-d2ceb0db7b7a', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'x-content-type-options': 'nosniff', 'Date': 'Tue, 04 Jul 2023 10:19:37 GMT'} 127.0.0.1 - - [04/Jul/2023 19:19:38] "POST /chat HTTP/1.1" 500 - INFO:werkzeug:127.0.0.1 - - [04/Jul/2023 19:19:38] "POST /chat HTTP/1.1" 500 -

Expected/desired behavior

OS and Version?

Windows 11

azd version?

azd version 1.0.2

Versions

Mention any other details that might be useful


Thanks! We'll be in touch soon.

funny1853 avatar Jul 04 '23 10:07 funny1853

Same error here.

marceloricciardi avatar Jul 05 '23 00:07 marceloricciardi

@funny1853 Please, did you manage to solve the problem?

marceloricciardi avatar Jul 05 '23 19:07 marceloricciardi

one more case here - same issue on : M1 Air Contributor role in Azure prior to execution of start.sh I've ran az login to determine correct Azure subscription Errors are 100% exact.

weasel4o avatar Jul 12 '23 08:07 weasel4o

It seems like something isn't correct with the OpenAI instance.

One thing you could do is check .azure/YOUR-ENV-NAME/.env and inspect the OpenAI related variables. Here's what mine looks like:

AZURE_ENV_NAME="bothgpt"
AZURE_FORMRECOGNIZER_RESOURCE_GROUP="rg-bothgpt"
AZURE_FORMRECOGNIZER_SERVICE="cog-fr-xenf7xvucmwaw"
AZURE_LOCATION="eastus"
AZURE_OPENAI_CHATGPT_DEPLOYMENT="chat"
AZURE_OPENAI_GPT_DEPLOYMENT="davinci"
AZURE_OPENAI_RESOURCE_GROUP="rg-bothgpt"
AZURE_OPENAI_SERVICE="cog-xenf7xvucmwaw"
AZURE_RESOURCE_GROUP="rg-bothgpt"
AZURE_SEARCH_INDEX="gptkbindex"
AZURE_SEARCH_SERVICE="gptkb-xenf7xvucmwaw"
AZURE_SEARCH_SERVICE_RESOURCE_GROUP="rg-bothgpt"
AZURE_STORAGE_ACCOUNT="stxenf7xvucmwaw"
AZURE_STORAGE_CONTAINER="content"
AZURE_STORAGE_RESOURCE_GROUP="rg-bothgpt"

I can then go into Azure Portal for the "rg-bothgpt" resource group, confirm there's an OpenAI service named "cog-xenf7xvucmwaw" and that it has two deployments.

Screenshot 2023-07-12 at 7 14 10 AM Screenshot 2023-07-12 at 7 15 00 AM

You can also inspect Access control to make sure "my access" includes an OpenAI role: Screenshot 2023-07-12 at 7 15 56 AM

If all looks good at this point, I'd suggest going into OpenAI studio, using the playground, then generating code in the playground and seeing if it runs locally.

pamelafox avatar Jul 12 '23 14:07 pamelafox

same problem here can run locally on some devices, but not on some other, using the same resource. Any progress?

Xiang-CH avatar Aug 01 '23 08:08 Xiang-CH

@Xiang-CH Can you be specific about what error you're seeing, and where you're seeing it? Please paste logs and note regions.

pamelafox avatar Aug 01 '23 12:08 pamelafox

@pamelafox thank you for responding, the region is east-us, the error is:

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'}

It worked on a friend's local environment with the same code, the same resources, the same role assignments,and the same environment variable.

Xiang-CH avatar Aug 02 '23 05:08 Xiang-CH

@Xiang-CH Hm. Which line of code is producing that error? Here's what I suggest for debugging it:

  1. Isolate that line of code into a Python file and try running it on its own, with all the same settings you're using in app.py (i.e. AzureDefaultCredential)
  2. Try using Azure OpenAI studio for the same deployment, and copy the generated Code from the studio. Run that locally and compare the results.

Usually if I do that, I can discover what's wrong with my local environment.

pamelafox avatar Aug 02 '23 21:08 pamelafox

@Xiang-CH I ran into the same error today in fact, and I followed my suggested steps for debugging it, and I realized that openai.api_base was not set correctly. Another thing that helps is to enable debug-level logging of the app, as it will show you the request URLs and data sent to the openAI SDK.

logging.basicConfig(level=logging.DEBUG)

pamelafox avatar Aug 03 '23 16:08 pamelafox

Faced the same error today, fixed it by specifying the default env name in config.json present inside .azure. image

Changed it to my env name ('demo' in my case) Initially it was pointing to "Azure-Generative" , which did not have the complete .env file image

Hope it helps :)

sohamok avatar Sep 06 '23 08:09 sohamok

I am using macOS, and to simplify the startup script in start.sh, I started directly from bash with the ./backend_env/bin/python -m quart --app main:app run --port 50505 --reload command. I got the exact same error.

Just before the error, I printed the values of the openai settings and found that the values set in openai.api_base were different.

print(openai.api_base, openai.api_version, openai.api_type, openai.api_key)
chat_completion = await openai.ChatCompletion.acreate(
...

Finally, it turned out that the cause was that I had not executed Loading azd .env file from current environment section in the start.sh script, so I changed it to execute this command to load .azure/YOUR-ENV-NAME/.env into the environment variable and then start the backend server, and it worked fine.

nohanaga avatar Sep 07 '23 15:09 nohanaga

For me it was because I was logged in to az cli with a different account. Switching to the account which had access to OpenAI deployment fixed the issue.

waqassiddiqi avatar Sep 09 '23 13:09 waqassiddiqi

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this issue will be closed.

github-actions[bot] avatar Dec 18 '23 01:12 github-actions[bot]