danny-avila / rag_api

ID-based RAG FastAPI: Integration with Langchain and PostgreSQL/pgvector
https://librechat.ai/
143 stars 60 forks source link

fastapi.exceptions.HTTPException: 401: Missing or invalid Authorization header #38

Closed V3YNjKbFGLSQ0FzpOu1s closed 1 month ago

V3YNjKbFGLSQ0FzpOu1s commented 1 month ago

I received the following warning message when I started Librechat: warn: RAG API is either not running or not reachable at http://127.0.0.1:8000, you may experience errors with file uploads. Then I decided to set up the RAG API. However, Librechat still couldn't connect to the RAG API. Additionally, when I attempted to access http://127.0.0.1:8000/ through my browser, I encountered the error message below:

2024-05-18 14:36:57,372 - root - INFO - Initialized embeddings of type: <class 'langchain_openai.embeddings.base.OpenAIEmbeddings'>
/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/langchain_community/vectorstores/pgvector.py:322: LangChainPendingDeprecationWarning: Please use JSONB instead of JSON for metadata. This change will allow for more efficient querying that involves filtering based on metadata.Please note that filtering operators have been changed when using JSOB metadata to be prefixed with a $ sign to avoid name collisions with columns. If you're using an existing database, you will need to create adb migration for your metadata column to be JSONB and update your queries to use the new operators. 
  warn_deprecated(
INFO:     Started server process [10921]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
ERROR:    Exception in ASGI application
  + Exception Group Traceback (most recent call last):
  |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 87, in collapse_excgroups
  |     yield
  |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 190, in __call__
  |     async with anyio.create_task_group() as task_group:
  |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 678, in __aexit__
  |     raise BaseExceptionGroup(
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
    |     result = await app(  # type: ignore[func-returns-value]
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
    |     return await self.app(scope, receive, send)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    |     await super().__call__(scope, receive, send)
    |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    |     await self.middleware_stack(scope, receive, send)
    |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    |     raise exc
    |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    |     await self.app(scope, receive, _send)
    |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    |     with collapse_excgroups():
    |   File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    |     self.gen.throw(typ, value, traceback)
    |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    |     raise exc
    |   File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
    |     response = await self.dispatch_func(request, call_next)
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/user/LibreChat/rag_api/middleware.py", line 23, in security_middleware
    |     raise HTTPException(status_code=401, detail="Missing or invalid Authorization header")
    | fastapi.exceptions.HTTPException: 401: Missing or invalid Authorization header
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "/usr/lib/python3.11/contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "/home/user/LibreChat/rag_api/.venv/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
    response = await self.dispatch_func(request, call_next)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/LibreChat/rag_api/middleware.py", line 23, in security_middleware
    raise HTTPException(status_code=401, detail="Missing or invalid Authorization header")
fastapi.exceptions.HTTPException: 401: Missing or invalid Authorization header
INFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
INFO:     Finished server process [10921]

The content of the .env file:

DB_HOST=xxx
POSTGRES_DB=xxx
POSTGRES_USER=xxx
POSTGRES_PASSWORD=xxx
RAG_OPENAI_API_KEY=xxx
JWT_SECRET=xxx

and I set RAG_API_URL=127.0.0.1:8000 in the .env file of Librechat. Is there something missing in my setup?

UPDATE: It did work when I set RAG_API_URL=http://127.0.0.1:8000 and I can chat with my documents.