From 631c357091988ae852ae600616c0f9098b6eabcf Mon Sep 17 00:00:00 2001 From: Maor Friedman Date: Tue, 29 Jul 2025 12:19:48 +0300 Subject: [PATCH] llama-stack persistence --- Containerfile.add_llama_to_lightspeed | 2 + Containerfile.assisted-chat | 2 +- assisted-chat-pod.yaml | 26 ++++++++++ config/llama_stack_client_config.yaml | 34 ++++++++++---- template.yaml | 68 +++++++++++++++++++++++---- 5 files changed, 113 insertions(+), 19 deletions(-) diff --git a/Containerfile.add_llama_to_lightspeed b/Containerfile.add_llama_to_lightspeed index bf1b287..4764209 100644 --- a/Containerfile.add_llama_to_lightspeed +++ b/Containerfile.add_llama_to_lightspeed @@ -19,6 +19,8 @@ RUN python3.12 -m pip install sqlalchemy RUN python3.12 -m pip install mcp +RUN python3.12 -m pip install psycopg2-binary + # Patch llama-stack with an important fix RUN microdnf install -y patch RUN cd /app-root/llama-stack && \ diff --git a/Containerfile.assisted-chat b/Containerfile.assisted-chat index 4037c1b..63c6185 100644 --- a/Containerfile.assisted-chat +++ b/Containerfile.assisted-chat @@ -3,7 +3,7 @@ FROM quay.io/lightspeed-core/lightspeed-stack:dev-20250728-f6cc203 RUN python3 -m ensurepip --default-pip && pip install --upgrade pip -RUN python3 -m pip install pyyaml pyaml litellm sqlalchemy mcp +RUN python3 -m pip install pyyaml pyaml litellm sqlalchemy mcp psycopg2-binary # Patch llama-stack with an important fix USER root diff --git a/assisted-chat-pod.yaml b/assisted-chat-pod.yaml index b1e8e5c..acc3f71 100644 --- a/assisted-chat-pod.yaml +++ b/assisted-chat-pod.yaml @@ -9,6 +9,16 @@ spec: env: - name: GEMINI_API_KEY value: ${GEMINI_API_KEY} + - name: LLAMA_STACK_POSTGRES_HOST + value: localhost + - name: LLAMA_STACK_POSTGRES_PORT + value: "5432" + - name: LLAMA_STACK_POSTGRES_USER + value: llamastack + - name: LLAMA_STACK_POSTGRES_PASSWORD + value: llamastack + - name: LLAMA_STACK_POSTGRES_NAME + value: llamastack ports: - containerPort: 8090 hostPort: 8090 @@ -62,8 +72,24 @@ spec: - mountPath: /systemprompt.txt name: config subPath: systemprompt.txt + - name: postgres + image: registry.redhat.io/rhel9/postgresql-16:latest + env: + - name: POSTGRESQL_USER + value: llamastack + - name: POSTGRESQL_PASSWORD + value: llamastack + - name: POSTGRESQL_DATABASE + value: llamastack + ports: + - containerPort: 5432 + volumeMounts: + - name: pgdata + mountPath: /var/lib/pgsql/data volumes: - name: config hostPath: path: ./config type: Directory + - name: pgdata + emptyDir: {} diff --git a/config/llama_stack_client_config.yaml b/config/llama_stack_client_config.yaml index c73768e..dc26cb1 100644 --- a/config/llama_stack_client_config.yaml +++ b/config/llama_stack_client_config.yaml @@ -25,12 +25,19 @@ providers: provider_type: inline::meta-reference config: persistence_store: - type: sqlite - namespace: null - db_path: ${env.SQLITE_STORE_DIR:=/tmp/.llama/distributions/starter}/agents_store.db + type: postgres + host: ${env.POSTGRES_HOST:=localhost} + port: ${env.POSTGRES_PORT:=5432} + db: ${env.POSTGRES_DB:=llamastack} + user: ${env.POSTGRES_USER:=llamastack} + password: ${env.POSTGRES_PASSWORD:=llamastack} responses_store: - type: sqlite - db_path: ${env.SQLITE_STORE_DIR:=/tmp/.llama/distributions/starter}/responses_store.db + type: postgres + host: ${env.POSTGRES_HOST:=localhost} + port: ${env.POSTGRES_PORT:=5432} + db: ${env.POSTGRES_DB:=llamastack} + user: ${env.POSTGRES_USER:=llamastack} + password: ${env.POSTGRES_PASSWORD:=llamastack} telemetry: - provider_id: meta-reference provider_type: inline::meta-reference @@ -55,11 +62,20 @@ providers: provider_type: remote::model-context-protocol config: {} metadata_store: - type: sqlite - db_path: ${env.SQLITE_STORE_DIR:=/tmp/.llama/distributions/starter}/registry.db + type: postgres + host: ${env.POSTGRES_HOST:=localhost} + port: ${env.POSTGRES_PORT:=5432} + db: ${env.POSTGRES_DB:=llamastack} + user: ${env.POSTGRES_USER:=llamastack} + password: ${env.POSTGRES_PASSWORD:=llamastack} + table_name: llamastack_kvstore inference_store: - type: sqlite - db_path: ${env.SQLITE_STORE_DIR:=/tmp/.llama/distributions/starter}/inference_store.db + type: postgres + host: ${env.POSTGRES_HOST:=localhost} + port: ${env.POSTGRES_PORT:=5432} + db: ${env.POSTGRES_DB:=llamastack} + user: ${env.POSTGRES_USER:=llamastack} + password: ${env.POSTGRES_PASSWORD:=llamastack} models: - metadata: {} model_id: gemini/gemini-2.0-flash diff --git a/template.yaml b/template.yaml index 8846807..9efce00 100644 --- a/template.yaml +++ b/template.yaml @@ -84,6 +84,9 @@ parameters: - name: LLAMA_STACK_SERVER_PORT value: "8321" description: "Port number for the embedded Llama Stack server" +- name: LLAMA_STACK_DB_SECRET_NAME + value: "llama-stack-db" + description: "Name of the Kubernetes secret containing the llama-stack database credentials" - name: SSO_BASE_URL value: "https://sso.redhat.com/auth/realms/redhat-external" description: "SSO Base URL" @@ -238,12 +241,19 @@ objects: provider_type: inline::meta-reference config: persistence_store: - type: sqlite - namespace: null - db_path: ${STORAGE_MOUNT_PATH}/sqlite/agents_store.db + type: postgres + host: ${env.LLAMA_STACK_POSTGRES_HOST} + port: ${env.LLAMA_STACK_POSTGRES_PORT} + db: ${env.LLAMA_STACK_POSTGRES_NAME} + user: ${env.LLAMA_STACK_POSTGRES_USER} + password: ${env.LLAMA_STACK_POSTGRES_PASSWORD} responses_store: - type: sqlite - db_path: ${STORAGE_MOUNT_PATH}/sqlite/responses_store.db + type: postgres + host: ${env.LLAMA_STACK_POSTGRES_HOST} + port: ${env.LLAMA_STACK_POSTGRES_PORT} + db: ${env.LLAMA_STACK_POSTGRES_NAME} + user: ${env.LLAMA_STACK_POSTGRES_USER} + password: ${env.LLAMA_STACK_POSTGRES_PASSWORD} telemetry: - provider_id: meta-reference provider_type: inline::meta-reference @@ -268,11 +278,20 @@ objects: provider_type: remote::model-context-protocol config: {} metadata_store: - type: sqlite - db_path: ${STORAGE_MOUNT_PATH}/sqlite/registry.db + type: postgres + host: ${env.LLAMA_STACK_POSTGRES_HOST} + port: ${env.LLAMA_STACK_POSTGRES_PORT} + db: ${env.LLAMA_STACK_POSTGRES_NAME} + user: ${env.LLAMA_STACK_POSTGRES_USER} + password: ${env.LLAMA_STACK_POSTGRES_PASSWORD} + table_name: llamastack_kvstore inference_store: - type: sqlite - db_path: ${STORAGE_MOUNT_PATH}/sqlite/inference_store.db + type: postgres + host: ${env.LLAMA_STACK_POSTGRES_HOST} + port: ${env.LLAMA_STACK_POSTGRES_PORT} + db: ${env.LLAMA_STACK_POSTGRES_NAME} + user: ${env.LLAMA_STACK_POSTGRES_USER} + password: ${env.LLAMA_STACK_POSTGRES_PASSWORD} models: - metadata: {} model_id: ${LLAMA_STACK_DEFAULT_MODEL} @@ -335,6 +354,37 @@ objects: value: ${LLAMA_STACK_OTEL_SERVICE_NAME} - name: LLAMA_STACK_TELEMETRY_SINKS value: ${LLAMA_STACK_TELEMETRY_SINKS} + - name: LLAMA_STACK_POSTGRES_HOST + valueFrom: + secretKeyRef: + name: ${LLAMA_STACK_DB_SECRET_NAME} + key: db.host + - name: LLAMA_STACK_POSTGRES_PORT + valueFrom: + secretKeyRef: + name: ${LLAMA_STACK_DB_SECRET_NAME} + key: db.port + - name: LLAMA_STACK_POSTGRES_NAME + valueFrom: + secretKeyRef: + name: ${LLAMA_STACK_DB_SECRET_NAME} + key: db.name + - name: LLAMA_STACK_POSTGRES_USER + valueFrom: + secretKeyRef: + name: ${LLAMA_STACK_DB_SECRET_NAME} + key: db.user + - name: LLAMA_STACK_POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: ${LLAMA_STACK_DB_SECRET_NAME} + key: db.password + - name: LLAMA_STACK_POSTGRES_CA_CERT + valueFrom: + secretKeyRef: + name: ${LLAMA_STACK_DB_SECRET_NAME} + key: db.ca_cert + optional: true resources: limits: memory: ${MEMORY_LIMIT}