Azure-Samples / azure-search-openai-demo

A sample app for the Retrieval-Augmented Generation pattern running in Azure, using Azure AI Search for retrieval and Azure OpenAI large language models to power ChatGPT-style and Q&A experiences.
https://azure.microsoft.com/products/search
MIT License
5.89k stars 4.03k forks source link

TypeError: Cannot read properties of undefined (reading '0') error from chat completion #770

Open mattjames1978 opened 11 months ago

mattjames1978 commented 11 months ago

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

Ask a question and submit on chat with your data page. Error in response. When clicking on ask a question the completion and response is received ok from data. Not sure what the issue is, logs below

Any log messages given by the failure

2023-10-10T10:05:43.130337042Z [2023-10-10 10:05:43 +0000] [74] [ERROR] Exception in ASGI application 2023-10-10T10:05:43.131131041Z Traceback (most recent call last): 2023-10-10T10:05:43.131141341Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 426, in run_asgi 2023-10-10T10:05:43.131145641Z result = await app( # type: ignore[func-returns-value] 2023-10-10T10:05:43.131148941Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in call 2023-10-10T10:05:43.131152441Z return await self.app(scope, receive, send) 2023-10-10T10:05:43.131155741Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/quart/app.py", line 1620, in call 2023-10-10T10:05:43.131159041Z await self.asgi_app(scope, receive, send) 2023-10-10T10:05:43.131162341Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/opentelemetry/instrumentation/asgi/init.py", line 596, in call 2023-10-10T10:05:43.131174841Z await self.app(scope, otel_receive, otel_send) 2023-10-10T10:05:43.131178341Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/quart/app.py", line 1646, in asgi_app 2023-10-10T10:05:43.131181441Z await asgi_handler(receive, send) 2023-10-10T10:05:43.131184741Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/quart/asgi.py", line 52, in call 2023-10-10T10:05:43.131187841Z raise_task_exceptions(done) 2023-10-10T10:05:43.131190741Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/quart/utils.py", line 187, in raise_task_exceptions 2023-10-10T10:05:43.131193941Z raise task.exception() 2023-10-10T10:05:43.131196841Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/quart/asgi.py", line 107, in handle_request 2023-10-10T10:05:43.131199941Z await asyncio.wait_for(self._send_response(send, response), timeout=timeout) 2023-10-10T10:05:43.131203041Z File "/opt/python/3.10.12/lib/python3.10/asyncio/tasks.py", line 408, in wait_for 2023-10-10T10:05:43.131206041Z return await fut 2023-10-10T10:05:43.131209041Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/quart/asgi.py", line 134, in _send_response 2023-10-10T10:05:43.131235041Z async for data in response_body: 2023-10-10T10:05:43.131238341Z File "/tmp/8dbc9762d29380d/app.py", line 127, in format_as_ndjson 2023-10-10T10:05:43.131241441Z async for event in r: 2023-10-10T10:05:43.131244541Z File "/tmp/8dbc9762d29380d/approaches/chatreadretrieveread.py", line 237, in run_with_streaming 2023-10-10T10:05:43.131247741Z extra_info, chat_coroutine = await self.run_until_final_call( 2023-10-10T10:05:43.131250941Z File "/tmp/8dbc9762d29380d/approaches/chatreadretrieveread.py", line 119, in run_until_final_call 2023-10-10T10:05:43.131256141Z chat_completion = await openai.ChatCompletion.acreate( 2023-10-10T10:05:43.131259541Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/openai/api_resources/chat_completion.py", line 45, in acreate 2023-10-10T10:05:43.131262741Z return await super().acreate(*args, **kwargs) 2023-10-10T10:05:43.131265841Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/openai/api_resources/abstract/engine_apiresource.py", line 219, in acreate 2023-10-10T10:05:43.131269141Z response, , api_key = await requestor.arequest( 2023-10-10T10:05:43.131272141Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/openai/api_requestor.py", line 384, in arequest 2023-10-10T10:05:43.131275341Z resp, got_stream = await self._interpret_async_response(result, stream) 2023-10-10T10:05:43.131278541Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/openai/api_requestor.py", line 738, in _interpret_async_response 2023-10-10T10:05:43.131285441Z self._interpret_response_line( 2023-10-10T10:05:43.131288641Z File "/tmp/8dbc9762d29380d/antenv/lib/python3.10/site-packages/openai/api_requestor.py", line 775, in _interpret_response_line 2023-10-10T10:05:43.131295841Z raise self.handle_error_response( 2023-10-10T10:05:43.131299041Z openai.error.InvalidRequestError: Unrecognized request argument supplied: functions

2023-10-10T10:05:43.174373581Z fail: Middleware[0] 2023-10-10T10:05:43.174412381Z Failed to forward request to http://169.254.130.33:8000. Encountered a System.IO.IOException exception after 1767.901ms with message: The response ended prematurely.. Check application logs to verify the application is properly handling HTTP traffic.

Expected/desired behavior

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)

azd version?

run azd version and copy paste here. latest

Versions

occurs with Python 3.10 and 3.11 for dev container and app runtime.

Mention any other details that might be useful


Thanks! We'll be in touch soon.

error
working
mattjames1978 commented 11 months ago

other errors of interest, note using Chat GPT Model version 0301 and API verson 2023-07-01-preview due to location constraints and need to deploy to West Europe. 0613 not available in WEU.

2023-10-10T11:50:07.986027963Z raise self.handle_error_response( 2023-10-10T11:50:07.986031463Z openai.error.InvalidRequestError: Unrecognized request argument supplied: functions

2023-10-10T12:19:25.599143198Z [2023-10-10 12:19:25 +0000] [77] [ERROR] Exception in ASGI application 2023-10-10T12:19:25.599185098Z Traceback (most recent call last): 2023-10-10T12:19:25.599190698Z File "/tmp/8dbc983f225d8ca/antenv/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 426, in run_asgi

suma-sai-paluri commented 11 months ago

Hi @mattjames1978 I am also facing the same issues, I also deployed the application using 0301 and api version 2023-07-01. And the deployed app was able to respond in ask approach and no response in chat approach Screenshot 2023-10-10 153041

mattjames1978 commented 11 months ago

@suma-sai-paluri ok thanks, interesting, so we think it is related to the GPT model version we are using 0301. Thanks, hopefully Pamela and the team will come back with a solution for us. thanks

mattjames1978 commented 11 months ago

@suma-sai-paluri here is something I have tried which has resolved it. Comment out the functions in here

chatreadretrieveread.py

image

Also changed the API version to openai.api_version = "2023-05-15" in app.py Think this is not needed though as tried it without and still works.

It maybe that the 0301 model doesn't support the functions being called.

Give it a try I am not getting correct responses.

suma-sai-paluri commented 11 months ago

Thank you @mattjames1978 , i can now get the responses ,but i am curious to understand how and why are these functions useful and what are the repercussions of eliminating them.

mattjames1978 commented 11 months ago

@suma-sai-paluri yes definitely, let's leave this issue open and wait for feedback :)

pamelafox commented 11 months ago

Our Bicep file now creates models with version 0613- https://github.com/Azure-Samples/azure-search-openai-demo/blob/7b2e88733f1557aa5480f0b1324aee73ac4e2845/infra/main.bicep#L60

It is no longer possible to deploy 0301 version models anymore, so presumably you created it a while ago.

It's probably fine to not use functions for the query generation, but we may want to use functions for more aspects of the process as well, since it can add more structure to responses. For example, we may use functions to get follow-up questions returned in a more consistent format.

Could you update to 0613? That would enable you to use functions in this case and also future uses.

srbalakr commented 11 months ago

Yes, function call is not supported in 0301. Default Model version in repo is 0613 and funcation call is enabled by default. To disable it use funcation_call='none' https://github.com/Azure-Samples/azure-search-openai-demo/blob/7b2e88733f1557aa5480f0b1324aee73ac4e2845/app/backend/approaches/chatreadretrieveread.py#L127C1-L128C1

mattjames1978 commented 11 months ago

Hi @pamelafox, yes we have been using model version 0301 for a while as our organisation can only deploy to West Europe region in a Azure. So will disable the function until 0613 becomes available in West Europe our primary region. Does any one know when this will become available? I have asked Our MS DSE to find out for us.
Thanks

suma-sai-paluri commented 11 months ago

Thank you @pamelafox and @srbalakr for your responses

hyondi commented 11 months ago

Thank you all for the responses. I've tried all the solutions listed up here, but i'm still stuck with the error. ( i have changed the API version to openai.api_version = "2023-05-15" in app.py , updated the Bicep file version to 0613, commented out the functions in chatreadretrieveread.py) I wonder if anyone has the same issue with me.

suma-sai-paluri commented 11 months ago

hi @hyondi try changing the openai.api_version = "2023-05-15" in predocs.py also and check the model which you are using ,because in some regions the 0613 isn't available yet. If you have access to gpt 3.5 turbo 0301 only like me ,try changing the model version to 0301 in main.bicep file.

pamelafox commented 11 months ago

@hyondi Can you share the full traceback from the logs for your error? You may be experiencing a different issue than the other developers in the thread. Any OpenAI-related issue can result in "TypeError: Cannot read properties of undefined (reading '0') error from chat completion"

david-an-tran-pham commented 11 months ago

@suma-sai-paluri here is something I have tried which has resolved it. Comment out the functions in here

chatreadretrieveread.py

image

Also changed the API version to openai.api_version = "2023-05-15" in app.py Think this is not needed though as tried it without and still works.

It maybe that the 0301 model doesn't support the functions being called.

Give it a try I am not getting correct responses.

This fixed my issue, thank you so much! However, now my Citation page is always showing:

Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Does this happen to you to?

github-actions[bot] commented 8 months ago

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.