Let superadmins assign one OpenRouter model per task group.
Deploy Development / deploy (push) Successful in 53s
Test Suite / pytest-backend (push) Successful in 50s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 17s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 7m40s
Deploy Development / deploy (push) Successful in 53s
Test Suite / pytest-backend (push) Successful in 50s
Test Suite / lint-backend (push) Successful in 1s
Test Suite / build-frontend (push) Successful in 17s
Test Suite / k6 /health Baseline (push) Successful in 35s
Test Suite / playwright-tests (push) Failing after 7m40s
Reasoning, drafting, and matching prompts inherit that model, so each prompt does not need its own setting. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0431c9e160
commit
b537750671
14 files changed
+720
-65
No files matched your search
@@ -48,7 +48,7 @@ def _fetch_prompt_any(cur, prompt_id: int) -> Dict[str, Any]:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id, slug, display_name, description, template, category, output_format,
|
||||
output_schema, is_system_default, default_template, openrouter_model,
|
||||
output_schema, is_system_default, default_template, openrouter_model, model_role,
|
||||
active, sort_order, created_at, updated_at
|
||||
FROM ai_prompts WHERE id = %s
|
||||
""",
|
||||
@@ -96,7 +96,7 @@ def list_ai_prompts(session: dict = Depends(_require_superadmin)):
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id, slug, display_name, description, category, output_format, active,
|
||||
sort_order, is_system_default, default_template, openrouter_model
|
||||
sort_order, is_system_default, default_template, openrouter_model, model_role
|
||||
FROM ai_prompts
|
||||
ORDER BY sort_order ASC NULLS LAST, id ASC
|
||||
"""
|
||||
@@ -174,7 +174,7 @@ def update_ai_prompt(
|
||||
openrouter_model = %s, updated_at = NOW()
|
||||
WHERE id = %s
|
||||
RETURNING id, slug, display_name, description, template, category, output_format,
|
||||
output_schema, is_system_default, default_template, openrouter_model,
|
||||
output_schema, is_system_default, default_template, openrouter_model, model_role,
|
||||
active, sort_order,
|
||||
created_at, updated_at
|
||||
""",
|
||||
@@ -207,7 +207,7 @@ def reset_ai_prompt_template(prompt_id: int, session: dict = Depends(_require_su
|
||||
SET template = default_template, updated_at = NOW()
|
||||
WHERE id = %s AND default_template IS NOT NULL
|
||||
RETURNING id, slug, display_name, description, template, category, output_format,
|
||||
output_schema, is_system_default, default_template, openrouter_model,
|
||||
output_schema, is_system_default, default_template, openrouter_model, model_role,
|
||||
active, sort_order,
|
||||
created_at, updated_at
|
||||
""",
|
||||
|
||||
@@ -9,11 +9,12 @@ from __future__ import annotations
|
||||
from typing import Any, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from auth import require_auth
|
||||
from club_tenancy import is_superadmin
|
||||
from db import get_cursor, get_db, r2d
|
||||
from ai_model_roles import ROLE_KEYS, resolve_prompt_openrouter_model
|
||||
from openrouter_chat import (
|
||||
OpenRouterError,
|
||||
env_openrouter_model_id,
|
||||
@@ -36,6 +37,15 @@ class OpenRouterSettingsUpdate(BaseModel):
|
||||
openrouter_model: Optional[str] = Field(None, max_length=200)
|
||||
|
||||
|
||||
class OpenRouterRoleUpdate(BaseModel):
|
||||
openrouter_model: Optional[str] = Field(None, max_length=200)
|
||||
|
||||
|
||||
class OpenRouterPromptRoleUpdate(BaseModel):
|
||||
model_config = ConfigDict(protected_namespaces=())
|
||||
model_role: Optional[str] = Field(None, max_length=40)
|
||||
|
||||
|
||||
def _iso(value: Any) -> Optional[str]:
|
||||
if value is None:
|
||||
return None
|
||||
@@ -122,6 +132,172 @@ def put_openrouter_settings(
|
||||
return _settings_payload(stored, row.get("updated_at"))
|
||||
|
||||
|
||||
def _prompt_view(row: dict, role_models: dict, platform_model: Optional[str], env_model: str) -> dict:
|
||||
prompt_model = str(row.get("openrouter_model") or "").strip() or None
|
||||
role_key = str(row.get("model_role") or "").strip() or None
|
||||
effective, source = resolve_prompt_openrouter_model(
|
||||
prompt_model=prompt_model,
|
||||
role_model=role_models.get(role_key or ""),
|
||||
platform_model=platform_model,
|
||||
env_model=env_model,
|
||||
)
|
||||
return {
|
||||
"id": row.get("id"),
|
||||
"slug": row.get("slug"),
|
||||
"display_name": row.get("display_name"),
|
||||
"model_role": role_key,
|
||||
"openrouter_model": prompt_model,
|
||||
"effective_model": effective,
|
||||
"source": source,
|
||||
}
|
||||
|
||||
|
||||
def _load_role_overview(cur) -> dict:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT role_key, display_name, description, openrouter_model, sort_order
|
||||
FROM platform_ai_model_roles
|
||||
ORDER BY sort_order ASC, role_key ASC
|
||||
"""
|
||||
)
|
||||
role_rows = [r2d(r) if not isinstance(r, dict) else r for r in cur.fetchall()]
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id, slug, display_name, model_role, openrouter_model, sort_order
|
||||
FROM ai_prompts
|
||||
ORDER BY sort_order ASC NULLS LAST, id ASC
|
||||
"""
|
||||
)
|
||||
prompt_rows = [r2d(r) if not isinstance(r, dict) else r for r in cur.fetchall()]
|
||||
cur.execute("SELECT openrouter_model FROM platform_ai_settings WHERE id = 1")
|
||||
settings = r2d(cur.fetchone())
|
||||
platform_model = str((settings or {}).get("openrouter_model") or "").strip() or None
|
||||
env_model = env_openrouter_model_id()
|
||||
role_models = {
|
||||
str(row.get("role_key") or ""): str(row.get("openrouter_model") or "").strip() or None
|
||||
for row in role_rows
|
||||
}
|
||||
prompts = [_prompt_view(row, role_models, platform_model, env_model) for row in prompt_rows]
|
||||
roles = []
|
||||
for row in role_rows:
|
||||
key = str(row.get("role_key") or "")
|
||||
stored = role_models.get(key)
|
||||
effective, source = resolve_prompt_openrouter_model(
|
||||
prompt_model=None,
|
||||
role_model=stored,
|
||||
platform_model=platform_model,
|
||||
env_model=env_model,
|
||||
)
|
||||
roles.append(
|
||||
{
|
||||
"role_key": key,
|
||||
"display_name": row.get("display_name"),
|
||||
"description": row.get("description"),
|
||||
"openrouter_model": stored,
|
||||
"effective_model": effective,
|
||||
"source": source,
|
||||
"prompts": [p for p in prompts if p.get("model_role") == key],
|
||||
}
|
||||
)
|
||||
return {
|
||||
"roles": roles,
|
||||
"unassigned": [p for p in prompts if not p.get("model_role")],
|
||||
"platform_model": platform_model,
|
||||
"env_model": env_model,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/api/admin/openrouter/roles")
|
||||
def get_openrouter_roles(session: dict = Depends(_require_superadmin)):
|
||||
try:
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
return _load_role_overview(cur)
|
||||
except Exception as exc:
|
||||
if _missing_table(exc) or "platform_ai_model_roles" in str(exc).lower():
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail="Tabelle platform_ai_model_roles fehlt. Migration 098 ausführen.",
|
||||
) from exc
|
||||
raise
|
||||
|
||||
|
||||
@router.put("/api/admin/openrouter/roles/{role_key}")
|
||||
def put_openrouter_role(
|
||||
role_key: str,
|
||||
body: OpenRouterRoleUpdate,
|
||||
session: dict = Depends(_require_superadmin),
|
||||
):
|
||||
key = (role_key or "").strip()
|
||||
if key not in ROLE_KEYS:
|
||||
raise HTTPException(status_code=404, detail="Unbekannte Aufgabengruppe.")
|
||||
try:
|
||||
model = normalize_openrouter_model_id(body.openrouter_model)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
profile_id = session.get("profile_id")
|
||||
try:
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE platform_ai_model_roles
|
||||
SET openrouter_model = %s, updated_at = NOW(), updated_by_profile_id = %s
|
||||
WHERE role_key = %s
|
||||
RETURNING role_key
|
||||
""",
|
||||
(model, profile_id, key),
|
||||
)
|
||||
updated = cur.fetchone()
|
||||
if not updated:
|
||||
raise HTTPException(status_code=404, detail="Aufgabengruppe fehlt.")
|
||||
return _load_role_overview(cur)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as exc:
|
||||
if "platform_ai_model_roles" in str(exc).lower() or _missing_table(exc):
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail="Tabelle platform_ai_model_roles fehlt. Migration 098 ausführen.",
|
||||
) from exc
|
||||
raise
|
||||
|
||||
|
||||
@router.put("/api/admin/openrouter/prompts/{prompt_id}/role")
|
||||
def put_openrouter_prompt_role(
|
||||
prompt_id: int,
|
||||
body: OpenRouterPromptRoleUpdate,
|
||||
session: dict = Depends(_require_superadmin),
|
||||
):
|
||||
role = str(body.model_role or "").strip() or None
|
||||
if role and role not in ROLE_KEYS:
|
||||
raise HTTPException(status_code=400, detail="Unbekannte Aufgabengruppe.")
|
||||
try:
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute(
|
||||
"""
|
||||
UPDATE ai_prompts
|
||||
SET model_role = %s, updated_at = NOW()
|
||||
WHERE id = %s
|
||||
RETURNING id
|
||||
""",
|
||||
(role, prompt_id),
|
||||
)
|
||||
if not cur.fetchone():
|
||||
raise HTTPException(status_code=404, detail="Prompt nicht gefunden.")
|
||||
return _load_role_overview(cur)
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as exc:
|
||||
if "model_role" in str(exc).lower() or "platform_ai_model_roles" in str(exc).lower():
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail="Aufgabengruppen fehlen. Migration 098 ausführen.",
|
||||
) from exc
|
||||
raise
|
||||
|
||||
|
||||
@router.get("/api/admin/openrouter/models")
|
||||
def list_openrouter_models(
|
||||
refresh: bool = Query(False),
|
||||
|
||||
Reference in new issue
Block a user