arunwidjaja / openAIRAG

OpenAI Retrieval-Augmented Generation
0 stars 0 forks source link

ASGI Application Error when submitting query #1

Closed arunwidjaja closed 2 hours ago

arunwidjaja commented 3 hours ago

I submitted a simple query, "Where does Koh Hansu live?", to the application running locally but got this error message from Docker. The vector database is already copied to the Docker container

Docker log:

2024-09-29 17:40:40 INFO: Will watch for changes in these directories: ['/app'] 2024-09-29 17:40:40 INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit) 2024-09-29 17:40:40 INFO: Started reloader process [1] using WatchFiles 2024-09-29 17:40:41 INFO: Started server process [8] 2024-09-29 17:40:41 INFO: Waiting for application startup. 2024-09-29 17:40:41 INFO: Application startup complete. 2024-09-29 17:41:20 INFO: 172.17.0.1:41888 - "GET /docs HTTP/1.1" 200 OK 2024-09-29 17:41:20 INFO: 172.17.0.1:41888 - "GET /openapi.json HTTP/1.1" 200 OK 2024-09-29 17:41:33 /app/query_data.py:40: LangChainDeprecationWarning: The class Chroma was deprecated in LangChain 0.2.9 and will be removed in 1.0. An updated version of the class exists in the :class:~langchain-chroma package and should be used instead. To use it runpip install -U :class:~langchain-chroma and import as from :class:~langchain_chroma import Chroma``. 2024-09-29 17:41:33 db = Chroma(persist_directory=CHROMA_PATH, 2024-09-29 17:41:34 ⚠️ It looks like you upgraded from a version below 0.6 and could benefit from vacuuming your database. Run chromadb utils vacuum --help for more information. 2024-09-29 17:41:37 INFO: 172.17.0.1:40426 - "POST /submit_query HTTP/1.1" 500 Internal Server Error 2024-09-29 17:41:37 ERROR: Exception in ASGI application 2024-09-29 17:41:37 Traceback (most recent call last): 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 72, in map_httpcore_exceptions 2024-09-29 17:41:37 yield 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 236, in handle_request 2024-09-29 17:41:37 resp = self._pool.handle_request(req) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py", line 216, in handle_request 2024-09-29 17:41:37 raise exc from None 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpcore/_sync/connection_pool.py", line 196, in handle_request 2024-09-29 17:41:37 response = connection.handle_request( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpcore/_sync/connection.py", line 101, in handle_request 2024-09-29 17:41:37 return self._connection.handle_request(request) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 143, in handle_request 2024-09-29 17:41:37 raise exc 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 93, in handle_request 2024-09-29 17:41:37 self._send_request_headers(kwargs) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpcore/_sync/http11.py", line 151, in _send_request_headers 2024-09-29 17:41:37 with map_exceptions({h11.LocalProtocolError: LocalProtocolError}): 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/contextlib.py", line 158, in exit 2024-09-29 17:41:37 self.gen.throw(value) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions 2024-09-29 17:41:37 raise to_exc(exc) from exc 2024-09-29 17:41:37 httpcore.LocalProtocolError: Illegal header value b'Bearer ' 2024-09-29 17:41:37 2024-09-29 17:41:37 The above exception was the direct cause of the following exception: 2024-09-29 17:41:37 2024-09-29 17:41:37 Traceback (most recent call last): 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 983, in _request 2024-09-29 17:41:37 response = self._client.send( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 926, in send 2024-09-29 17:41:37 response = self._send_handling_auth( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 954, in _send_handling_auth 2024-09-29 17:41:37 response = self._send_handling_redirects( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 991, in _send_handling_redirects 2024-09-29 17:41:37 response = self._send_single_request(request) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpx/_client.py", line 1027, in _send_single_request 2024-09-29 17:41:37 response = transport.handle_request(request) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 235, in handle_request 2024-09-29 17:41:37 with map_httpcore_exceptions(): 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/contextlib.py", line 158, in exit 2024-09-29 17:41:37 self.gen.throw(value) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/httpx/_transports/default.py", line 89, in map_httpcore_exceptions 2024-09-29 17:41:37 raise mapped_exc(message) from exc 2024-09-29 17:41:37 httpx.LocalProtocolError: Illegal header value b'Bearer ' 2024-09-29 17:41:37 2024-09-29 17:41:37 The above exception was the direct cause of the following exception: 2024-09-29 17:41:37 2024-09-29 17:41:37 Traceback (most recent call last): 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi 2024-09-29 17:41:37 result = await app( # type: ignore[func-returns-value] 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in call 2024-09-29 17:41:37 return await self.app(scope, receive, send) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in call 2024-09-29 17:41:37 await super().call(scope, receive, send) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/applications.py", line 113, in call 2024-09-29 17:41:37 await self.middleware_stack(scope, receive, send) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/middleware/errors.py", line 187, in call 2024-09-29 17:41:37 raise exc 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165, in call 2024-09-29 17:41:37 await self.app(scope, receive, _send) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in call 2024-09-29 17:41:37 await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app 2024-09-29 17:41:37 raise exc 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app 2024-09-29 17:41:37 await app(scope, receive, sender) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 715, in call 2024-09-29 17:41:37 await self.middleware_stack(scope, receive, send) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 735, in app 2024-09-29 17:41:37 await route.handle(scope, receive, send) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 288, in handle 2024-09-29 17:41:37 await self.app(scope, receive, send) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 76, in app 2024-09-29 17:41:37 await wrap_app_handling_exceptions(app, request)(scope, receive, send) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/_exception_handler.py", line 62, in wrapped_app 2024-09-29 17:41:37 raise exc 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/_exception_handler.py", line 51, in wrapped_app 2024-09-29 17:41:37 await app(scope, receive, sender) 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/routing.py", line 73, in app 2024-09-29 17:41:37 response = await f(request) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/fastapi/routing.py", line 301, in app 2024-09-29 17:41:37 raw_response = await run_endpoint_function( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/fastapi/routing.py", line 214, in run_endpoint_function 2024-09-29 17:41:37 return await run_in_threadpool(dependant.call, values) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/starlette/concurrency.py", line 39, in run_in_threadpool 2024-09-29 17:41:37 return await anyio.to_thread.run_sync(func, args) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/anyio/to_thread.py", line 56, in run_sync 2024-09-29 17:41:37 return await get_async_backend().run_sync_in_worker_thread( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 2405, in run_sync_in_worker_thread 2024-09-29 17:41:37 return await future 2024-09-29 17:41:37 ^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 914, in run 2024-09-29 17:41:37 result = context.run(func, args) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/app/api_handler.py", line 26, in submit_query_endpoint 2024-09-29 17:41:37 query_response = query_rag(request.query_text) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/app/query_data.py", line 44, in query_rag 2024-09-29 17:41:37 results = db.similarity_search_with_relevance_scores(query_text, k=LLM_K) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/langchain_core/vectorstores/base.py", line 547, in similarity_search_with_relevance_scores 2024-09-29 17:41:37 docs_and_similarities = self._similarity_search_with_relevance_scores( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/langchain_core/vectorstores/base.py", line 495, in _similarity_search_with_relevance_scores 2024-09-29 17:41:37 docs_and_scores = self.similarity_search_with_score(query, k, **kwargs) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/langchain_community/vectorstores/chroma.py", line 439, in similarity_search_with_score 2024-09-29 17:41:37 query_embedding = self._embedding_function.embed_query(query) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/langchain_openai/embeddings/base.py", line 629, in embed_query 2024-09-29 17:41:37 return self.embed_documents([text])[0] 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/langchain_openai/embeddings/base.py", line 588, in embed_documents 2024-09-29 17:41:37 return self._get_len_safe_embeddings(texts, engine=engine) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/langchain_openai/embeddings/base.py", line 483, in _get_len_safe_embeddings 2024-09-29 17:41:37 response = self.client.create( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/openai/resources/embeddings.py", line 124, in create 2024-09-29 17:41:37 return self._post( 2024-09-29 17:41:37 ^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 1270, in post 2024-09-29 17:41:37 return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 947, in request 2024-09-29 17:41:37 return self._request( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 1007, in _request 2024-09-29 17:41:37 return self._retry_request( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 1085, in _retry_request 2024-09-29 17:41:37 return self._request( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 1007, in _request 2024-09-29 17:41:37 return self._retry_request( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 1085, in _retry_request 2024-09-29 17:41:37 return self._request( 2024-09-29 17:41:37 ^^^^^^^^^^^^^^ 2024-09-29 17:41:37 File "/usr/local/lib/python3.12/site-packages/openai/_base_client.py", line 1017, in _request 2024-09-29 17:41:37 raise APIConnectionError(request=request) from err 2024-09-29 17:41:37 openai.APIConnectionError: Connection error.

arunwidjaja commented 2 hours ago

needed to set api key in docker build command replace "LITERAL_KEY_HERE" with API Key

docker build --build-arg OPENAI_API_KEY=LITERAL_KEY_HERE -t openairag .