truefoundry / cognita

RAG (Retrieval Augmented Generation) Framework for building modular, open source applications for production by TrueFoundry
https://cognita.truefoundry.com
Apache License 2.0
3.32k stars 274 forks source link

Unable to finish the docker compose deployment without using `TFY_API_KEY` #382

Closed iridium-soda closed 2 weeks ago

iridium-soda commented 1 month ago

I’m trying to use Azure OpenAI as my LLM provider and the Mixedbread Remote API for reranking and embedding. I’m attempting to run the service using Docker Compose, but I’m encountering an issue preventing the service from starting.

I’m unsure whether there’s a configuration mistake on my end, or if the issue is related to environment variables. Specifically, I’m wondering if the TFY_API_KEY must be explicitly assigned for the service to run correctly.

Questions:

Are there any specific configurations or common pitfalls when integrating Azure OpenAI with Mixedbread API through Docker Compose? Is the TFY_API_KEY required for the deployment of the service? Could there be any other setup steps that I might have overlooked? Thank you for your assistance!

Here is my error message when trying to deploy:

WARN[0000] /home/cognita/docker-compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 7/7
 ✔ Network cognita_cognita-docker  Created                                                                                                                     0.1s 
 ✔ Container faster-whisper        Created                                                                                                                     0.1s 
 ✔ Container cognita-postgres      Created                                                                                                                     0.1s 
 ✔ Container qdrant                Created                                                                                                                     0.1s 
 ✔ Container unstructured-api      Created                                                                                                                     0.1s 
 ✔ Container cognita-backend       Created                                                                                                                     0.0s 
 ✔ Container cognita-frontend      Created                                                                                                                     5.2s 
Attaching to cognita-backend, cognita-frontend, cognita-postgres, faster-whisper, qdrant, unstructured-api
qdrant            |            _                 _    
qdrant            |   __ _  __| |_ __ __ _ _ __ | |_  
qdrant            |  / _` |/ _` | '__/ _` | '_ \| __| 
qdrant            | | (_| | (_| | | | (_| | | | | |_  
qdrant            |  \__, |\__,_|_|  \__,_|_| |_|\__| 
qdrant            |     |_|                           
qdrant            | 
qdrant            | Version: 1.8.4, build: 984f55d6
qdrant            | Access web UI at http://localhost:6333/dashboard
qdrant            | 
qdrant            | 2024-10-17T11:16:37.544433Z  INFO storage::content_manager::consensus::persistent: Loading raft state from ./storage/raft_state.json    
qdrant            | 2024-10-17T11:16:37.548291Z  INFO qdrant: Distributed mode disabled    
qdrant            | 2024-10-17T11:16:37.548317Z  INFO qdrant: Telemetry reporting enabled, id: bdc4aa04-e222-4b04-8d50-05bafb4df0b2    
qdrant            | 2024-10-17T11:16:37.549739Z  INFO qdrant::actix: TLS disabled for REST API    
qdrant            | 2024-10-17T11:16:37.549797Z  INFO qdrant::actix: Qdrant HTTP listening on 6333    
qdrant            | 2024-10-17T11:16:37.549802Z  INFO actix_server::builder: Starting 7 workers
qdrant            | 2024-10-17T11:16:37.549813Z  INFO actix_server::server: Actix runtime found; starting in Actix runtime
qdrant            | 2024-10-17T11:16:37.554359Z  INFO qdrant::tonic: Qdrant gRPC listening on 6334    
qdrant            | 2024-10-17T11:16:37.554379Z  INFO qdrant::tonic: TLS disabled for gRPC API    
cognita-postgres  | 
cognita-postgres  | PostgreSQL Database directory appears to contain a database; Skipping initialization
cognita-postgres  | 
cognita-postgres  | 2024-10-17 11:16:37.600 UTC [1] LOG:  starting PostgreSQL 13.16 (Debian 13.16-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
cognita-postgres  | 2024-10-17 11:16:37.600 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
cognita-postgres  | 2024-10-17 11:16:37.600 UTC [1] LOG:  listening on IPv6 address "::", port 5432
cognita-postgres  | 2024-10-17 11:16:37.608 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
cognita-postgres  | 2024-10-17 11:16:37.614 UTC [26] LOG:  database system was interrupted; last known up at 2024-10-17 11:12:35 UTC
cognita-postgres  | 2024-10-17 11:16:37.668 UTC [26] LOG:  database system was not properly shut down; automatic recovery in progress
cognita-postgres  | 2024-10-17 11:16:37.672 UTC [26] LOG:  redo starts at 0/1608950
cognita-postgres  | 2024-10-17 11:16:37.672 UTC [26] LOG:  invalid record length at 0/1608988: wanted 24, got 0
cognita-postgres  | 2024-10-17 11:16:37.672 UTC [26] LOG:  redo done at 0/1608950
cognita-postgres  | 2024-10-17 11:16:37.707 UTC [1] LOG:  database system is ready to accept connections
faster-whisper    | Uninstalled 1 package in 0.77ms
faster-whisper    | Installed 1 package in 0.92ms
faster-whisper    | INFO:     Started server process [25]
faster-whisper    | INFO:     Waiting for application startup.
faster-whisper    | INFO:     Application startup complete.
faster-whisper    | INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
faster-whisper    | 2024-10-17 11:16:43,895:INFO:httpx:_send_single_request:HTTP Request: GET https://api.gradio.app/gradio-messaging/en "HTTP/1.1 200 OK"
unstructured-api  | 2024-10-17 11:16:47,998 unstructured_api INFO Started Unstructured API
unstructured-api  | 2024-10-17 11:16:47,998 uvicorn.error INFO Started server process [7]
unstructured-api  | 2024-10-17 11:16:47,998 uvicorn.error INFO Waiting for application startup.
unstructured-api  | 2024-10-17 11:16:47,998 uvicorn.error INFO Application startup complete.
unstructured-api  | 2024-10-17 11:16:47,999 uvicorn.error INFO Uvicorn running on http://0.0.0.0:9500 (Press CTRL+C to quit)
cognita-backend   | Installing Prisma CLI
cognita-backend   |  * Install prebuilt node (23.0.0) ..... done.
cognita-backend   | Prisma schema loaded from backend/database/schema.prisma
cognita-backend   | Datasource "db": PostgreSQL database "cognita-config", schema "public" at "cognita-db:5432"
cognita-postgres  | 2024-10-17 11:17:29.892 UTC [42] LOG:  could not receive data from client: Connection reset by peer
cognita-backend   | 
cognita-backend   | The database is already in sync with the Prisma schema.
cognita-backend   | 
✔ Generated Prisma Client Python (v0.13.1) to ./../virtualenvs/venv/lib/python3.
cognita-backend   | 11/site-packages/prisma in 174ms
cognita-backend   | 
cognita-backend   | INFO:     Will watch for changes in these directories: ['/app']
cognita-backend   | INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
cognita-backend   | INFO:     Started reloader process [85] using WatchFiles
cognita-backend   | Process SpawnProcess-1:
cognita-backend   | Traceback (most recent call last):
cognita-backend   |   File "/usr/local/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
cognita-backend   |     self.run()
cognita-backend   |   File "/usr/local/lib/python3.11/multiprocessing/process.py", line 108, in run
cognita-backend   |     self._target(*self._args, **self._kwargs)
cognita-backend   |   File "/virtualenvs/venv/lib/python3.11/site-packages/uvicorn/_subprocess.py", line 76, in subprocess_started
cognita-backend   |     target(sockets=sockets)
cognita-backend   |   File "/virtualenvs/venv/lib/python3.11/site-packages/uvicorn/server.py", line 61, in run
cognita-backend   |     return asyncio.run(self.serve(sockets=sockets))
cognita-backend   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cognita-backend   |   File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
cognita-backend   |     return runner.run(main)
cognita-backend   |            ^^^^^^^^^^^^^^^^
cognita-backend   |   File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
cognita-backend   |     return self._loop.run_until_complete(task)
cognita-backend   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cognita-backend   |   File "uvloop/loop.pyx", line 1518, in uvloop.loop.Loop.run_until_complete
cognita-backend   |   File "/virtualenvs/venv/lib/python3.11/site-packages/uvicorn/server.py", line 68, in serve
cognita-backend   |     config.load()
cognita-backend   |   File "/virtualenvs/venv/lib/python3.11/site-packages/uvicorn/config.py", line 467, in load
cognita-backend   |     self.loaded_app = import_from_string(self.app)
cognita-backend   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cognita-backend   |   File "/virtualenvs/venv/lib/python3.11/site-packages/uvicorn/importer.py", line 21, in import_from_string
cognita-backend   |     module = importlib.import_module(module_str)
cognita-backend   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cognita-backend   |   File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
cognita-backend   |     return _bootstrap._gcd_import(name[level:], package, level)
cognita-backend   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cognita-backend   |   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
cognita-backend   |   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
cognita-backend   |   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
cognita-backend   |   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
cognita-backend   |   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
cognita-backend   |   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
cognita-backend   |   File "/app/backend/server/app.py", line 11, in <module>
cognita-backend   |     from backend.modules.query_controllers.query_controller import QUERY_CONTROLLER_REGISTRY
cognita-backend   |   File "/app/backend/modules/query_controllers/__init__.py", line 1, in <module>
cognita-backend   |     from backend.modules.query_controllers.example.controller import BasicRAGQueryController
cognita-backend   |   File "/app/backend/modules/query_controllers/example/controller.py", line 7, in <module>
cognita-backend   |     from backend.modules.query_controllers.base import BaseQueryController
cognita-backend   |   File "/app/backend/modules/query_controllers/base.py", line 15, in <module>
cognita-backend   |     from backend.modules.metadata_store.client import get_client
cognita-backend   |   File "/app/backend/modules/metadata_store/__init__.py", line 2, in <module>
cognita-backend   |     from backend.modules.metadata_store.prisma_store import PrismaStore
cognita-backend   |   File "/app/backend/modules/metadata_store/prisma_store.py", line 28, in <module>
cognita-backend   |     from backend.utils import TRUEFOUNDRY_CLIENT
cognita-backend   |   File "/app/backend/utils.py", line 16, in <module>
cognita-backend   |     TRUEFOUNDRY_CLIENT = get_tfy_client()
cognita-backend   |                          ^^^^^^^^^^^^^^^^
cognita-backend   |   File "/virtualenvs/venv/lib/python3.11/site-packages/truefoundry/ml/mlfoundry_api.py", line 1574, in get_client
cognita-backend   |     session = init_session()
cognita-backend   |               ^^^^^^^^^^^^^^
cognita-backend   |   File "/virtualenvs/venv/lib/python3.11/site-packages/truefoundry/ml/session.py", line 143, in init_session
cognita-backend   |     final_cred_provider = cred_provider()
cognita-backend   |                           ^^^^^^^^^^^^^^^
cognita-backend   |   File "/virtualenvs/venv/lib/python3.11/site-packages/truefoundry/common/credential_provider.py", line 34, in __init__
cognita-backend   |     raise Exception(
cognita-backend   | Exception: Value of TFY_API_KEY env var should be non-empty string
Gracefully stopping... (press Ctrl+C again to force)
dependency failed to start: container cognita-backend is unhealthy
iridium-soda commented 1 month ago

Also, here is my custom models_config.yaml:

model_providers:
  ############################ Local ############################################
  #   Uncomment this provider if you want to use local models providers         #
  #   using ollama and infinity model server                                    #
  ###############################################################################

  # - provider_name: local-ollama
  #   api_format: openai
  #   base_url: http://ollama-server:11434/v1/
  #   api_key_env_var: ""
  #   llm_model_ids:
  #     - "qwen2:1.5b"
  #   embedding_model_ids: []
  #   reranking_model_ids: []
  #   default_headers: {}

  # - provider_name: local-infinity
  #   api_format: openai
  #   base_url: http://infinity-server:7997/
  #   api_key_env_var: INFINITY_API_KEY
  #   llm_model_ids: []
  #   embedding_model_ids:
  #     - "mixedbread-ai/mxbai-embed-large-v1"
  #   reranking_model_ids:
  #     - "mixedbread-ai/mxbai-rerank-xsmall-v1"
  #   default_headers: {}

  # - provider_name: faster-whisper
  #   api_format: openai
  #   base_url: http://faster-whisper:8000
  #   api_key_env_var: ""
  #   llm_model_ids: []
  #   embedding_model_ids: []
  #   reranking_model_ids: []
  #   audio_model_ids:
  #     - "Systran/faster-distil-whisper-large-v3"
  #   default_headers: {}
############################ OpenAI ###########################################
#   Uncomment this provider if you want to use OpenAI as a models provider    #
#   Remember to set `OPENAI_API_KEY` in container environment                 #
###############################################################################

# - provider_name: openai
#   api_format: openai
#   api_key_env_var: OPENAI_API_KEY
#   llm_model_ids:
#     - "gpt-3.5-turbo"
#     - "gpt-4o"
#   embedding_model_ids:
#     - "text-embedding-3-small"
#     - "text-embedding-ada-002"
#   reranking_model_ids: []
#   default_headers: {}

############################ TrueFoundry ###########################################
#   Uncomment this provider if you want to use TrueFoundry as a models provider    #
#   Remember to set `TFY_API_KEY` in container environment                         #
####################################################################################

# - provider_name: truefoundry
#   api_format: openai
#   base_url: https://llm-gateway.truefoundry.com/api/inference/openai
#   api_key_env_var: TFY_API_KEY
#   llm_model_ids:
#     - "openai-main/gpt-4o-mini"
#     - "openai-main/gpt-4-turbo"
#     - "openai-main/gpt-3-5-turbo"
#   embedding_model_ids:
#     - "openai-main/text-embedding-3-small"
#     - "openai-main/text-embedding-ada-002"
#   reranking_model_ids: []
#   default_headers: {}
############################ Mixedbread ###########################################
#   Uncomment this provider if you want to use Mixedbread as a models provider    #
#   Remember to set `MIX_API_KEY` in container environment (./compose.env)        #
##################################################################################### 
  - provider_name: Mixedbread
    api_format: openai
    base_url: https://api.mixedbread.ai
    api_key_env_var: MIX_KEY
    llm_model_ids: []
    embedding_model_ids:
      - 'mixedbread-ai/mxbai-embed-large-v1'
    reranking_model_ids: 
      - "mixedbread-ai/mxbai-rerank-large-v1"
    default_headers: {}
############################ Azure ###########################################
#   Uncomment this provider if you want to use Azure as a models provider    #
#   Remember to set `AZURE_API_KEY` in container environment                 #
###############################################################################  
- provider_name: Azure
    api_format: openai
    base_url: AZURE_ENDPOINT
    api_key_env_var: AZURE_KEY
    llm_model_ids: 
      - 'gpt35-16k'
    embedding_model_ids: []
    reranking_model_ids: []
    default_headers: {}
FabrizioDG commented 1 month ago

Hi I had the same issue, and in my understanding it is necessary to create a truefoundry api key to make it work. Probably it should be specified in the readme.

iridium-soda commented 1 month ago

Hi I had the same issue, and in my understanding it is necessary to create a truefoundry api key to make it work. Probably it should be specified in the readme.

I used to think open-source projects wouldn’t typically require registration, but I understand if this is necessary here. That said, it would be great if this key requirement could be highlighted earlier in the documentation.

Apologies if my earlier message came off as a complaint! Could you kindly point me in the right direction to get the necessary variable? I wasn’t able to find the API key on truefoundry.cloud. Could it be the Cluster Token from the cluster instead?

FabrizioDG commented 1 month ago

Hi,

I am not a developer of this project so I don't want to say things which end up being not true, so let's wait for them to clarify this point about the necessity of using a truefoundry api key. I agree with you that it should be clarified in the readme.

Anyways what I did to make it work is to create an account on truefoundry (you cannot use your personal email, it must be an organization email like your company email.. Not sure if also university email might work) and give a name to the project or the name of your company. This will create an endpoint like https://your-project-name.truefoundry.cloud/

This should be set as TFY_HOST in the compose.env file. To generate an API key you have to click on "Settings" on the left of the truefoundry page after you logged in. If you don't see settings try to do "ctrl+-" to zoom out, because it is below "Integrations". In my default browser settings I couldn't see it, and I realized after a bit that zooming out I could see that button. There you can create a new personal access token that you copy paste in compose.env.

I am on free tier and I never put any credit card, the only thing is that I am not sure if my token will expire or not.

I hope this helps

iridium-soda commented 1 month ago

Hi,

I am not a developer of this project so I don't want to say things which end up being not true, so let's wait for them to clarify this point about the necessity of using a truefoundry api key. I agree with you that it should be clarified in the readme.

Anyways what I did to make it work is to create an account on truefoundry (you cannot use your personal email, it must be an organization email like your company email.. Not sure if also university email might work) and give a name to the project or the name of your company. This will create an endpoint like https://your-project-name.truefoundry.cloud/

This should be set as TFY_HOST in the compose.env file. To generate an API key you have to click on "Settings" on the left of the truefoundry page after you logged in. If you don't see settings try to do "ctrl+-" to zoom out, because it is below "Integrations". In my default browser settings I couldn't see it, and I realized after a bit that zooming out I could see that button. There you can create a new personal access token that you copy paste in compose.env.

I am on free tier and I never put any credit card, the only thing is that I am not sure if my token will expire or not.

I hope this helps

Thank you so much for your kind help! I’m sure it will be really helpful for me 😊.

chiragjn commented 2 weeks ago

Hello, This seems to have been introduced recently, looks like we have unintentionally created a hard dependency on TFY_API_KEY

We'll fix this shortly. You should not need to sign up with TrueFoundry, apologies for the inconvenience

mnvsk97 commented 2 weeks ago

Hello @FabrizioDG @iridium-soda,

This issue has been fixed. Please give it a try and let us know in case of issues. Thanks !