synops/migrations/034_model_config.sql
vegard 052444c2a0 API-nøkler: test eksisterende nøkler + model_config tabell
- Ny rute POST /admin/api-keys/test-existing: dekrypterer og tester
  lagret nøkkel by ID (bruker SYNOPS_MASTER_KEY)
- Test-knapp per nøkkel i admin-UI (ved siden av deaktiver/slett)
- Testresultat vises inline (grønn/rød)
- model_config tabell: erstatter LiteLLM YAML, mapper alias → provider + modell
- model_pricing tabell: kostnadsestimat for admin-UI

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 07:08:52 +00:00

42 lines
2.2 KiB
SQL

-- Model config: erstatter LiteLLM YAML.
-- Mapper alias (synops/low, synops/high) → provider + modell.
-- Fallback-kjede via priority.
CREATE TABLE IF NOT EXISTS model_config (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
alias TEXT NOT NULL, -- "synops/low", "synops/high", etc.
provider TEXT NOT NULL, -- "openrouter", "anthropic", "gemini", "xai", "openai", "ollama"
model TEXT NOT NULL, -- "google/gemini-2.5-flash", "anthropic/claude-sonnet-4", etc.
priority SMALLINT NOT NULL DEFAULT 1, -- lavere = foretrukket. Fallback ved feil.
is_active BOOLEAN NOT NULL DEFAULT true,
max_tokens INTEGER DEFAULT 4096,
description TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_model_config_alias ON model_config(alias, priority) WHERE is_active = true;
-- Seed: standard modell-konfigurasjon
INSERT INTO model_config (alias, provider, model, priority, description) VALUES
('synops/low', 'openrouter', 'google/gemini-2.5-flash', 1, 'Billig, rask — rutine, klassifisering'),
('synops/medium', 'openrouter', 'google/gemini-2.5-flash', 1, 'Mellomting — implementering, analyse'),
('synops/high', 'openrouter', 'anthropic/claude-sonnet-4', 1, 'Resonering, kreativitet, presisjon'),
('synops/high', 'openrouter', 'google/gemini-2.5-flash', 2, 'Fallback for synops/high'),
('synops/extreme', 'openrouter', 'anthropic/claude-opus-4', 1, 'Tung arkitektur og beslutninger')
ON CONFLICT DO NOTHING;
-- Modellpriser for kostnadsestimat i admin-UI
CREATE TABLE IF NOT EXISTS model_pricing (
provider TEXT NOT NULL,
model TEXT NOT NULL,
input_price_per_m NUMERIC, -- pris per million input-tokens
output_price_per_m NUMERIC, -- pris per million output-tokens
updated_at TIMESTAMPTZ DEFAULT now(),
PRIMARY KEY (provider, model)
);
INSERT INTO model_pricing (provider, model, input_price_per_m, output_price_per_m) VALUES
('openrouter', 'google/gemini-2.5-flash', 0.15, 0.60),
('openrouter', 'anthropic/claude-sonnet-4', 3.00, 15.00),
('openrouter', 'anthropic/claude-opus-4', 15.00, 75.00)
ON CONFLICT DO NOTHING;