# llm-svc — LLM providers microservice
# API: GET/POST/PATCH/DELETE /api/v1/providers, models CRUD
# Используется chat-svc, media-svc, suggestions-svc и др.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: llm-svc
  namespace: gooseek
spec:
  replicas: 1
  selector:
    matchLabels:
      app: llm-svc
  template:
    metadata:
      labels:
        app: llm-svc
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "3020"
        prometheus.io/path: "/metrics"
    spec:
      containers:
        - name: llm-svc
          image: gooseek/llm-svc:latest
          imagePullPolicy: Never
          ports:
            - containerPort: 3020
          env:
            - name: PORT
              value: "3020"
            - name: DATA_DIR
              value: "/app/data"
            - name: LLM_PROVIDER
              valueFrom:
                configMapKeyRef:
                  name: llm-svc-config
                  key: llm-provider
            - name: OLLAMA_BASE_URL
              valueFrom:
                configMapKeyRef:
                  name: llm-svc-config
                  key: ollama-base-url
                  optional: true
            - name: OPENAI_API_KEY
              valueFrom:
                secretKeyRef:
                  name: llm-credentials
                  key: openai-api-key
                  optional: true
            - name: TIMEWEB_API_BASE_URL
              valueFrom:
                configMapKeyRef:
                  name: llm-svc-config
                  key: timeweb-api-base-url
                  optional: true
            - name: LLM_CHAT_MODEL
              valueFrom:
                configMapKeyRef:
                  name: llm-svc-config
                  key: llm-chat-model
                  optional: true
            - name: TIMEWEB_X_PROXY_SOURCE
              valueFrom:
                configMapKeyRef:
                  name: llm-svc-config
                  key: timeweb-x-proxy-source
                  optional: true
            - name: TIMEWEB_AGENT_ACCESS_ID
              valueFrom:
                secretKeyRef:
                  name: llm-credentials
                  key: timeweb-agent-access-id
                  optional: true
            - name: TIMEWEB_API_KEY
              valueFrom:
                secretKeyRef:
                  name: llm-credentials
                  key: timeweb-api-key
                  optional: true
          volumeMounts:
            - name: llm-data
              mountPath: /app/data
          livenessProbe:
            httpGet:
              path: /health
              port: 3020
            initialDelaySeconds: 10
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /ready
              port: 3020
            initialDelaySeconds: 5
            periodSeconds: 5
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: 500m
              memory: 512Mi
      volumes:
        - name: llm-data
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: llm-svc
  namespace: gooseek
spec:
  selector:
    app: llm-svc
  ports:
    - port: 3020
      targetPort: 3020
---
# ConfigMap: llm-provider = ollama | timeweb
# Для timeweb: создайте Secret llm-credentials с ключами timeweb-agent-access-id, timeweb-api-key
apiVersion: v1
kind: ConfigMap
metadata:
  name: llm-svc-config
  namespace: gooseek
data:
  llm-provider: "timeweb"
  ollama-base-url: "http://host.docker.internal:11434"
  timeweb-api-base-url: "https://api.timeweb.cloud"
  llm-chat-model: "gpt-4"
