Summarizing web search results falls back to DEFAULT_MODEL, so a local Ollama model ends up doing it and the call can fail — which surfaces only as "保存できる要約なし" in the chat. Make SEARCH_SUMMARY_MODEL settable at runtime: add it to the settings allowlist and read it from os.environ on each call (knowledge._summary_model), the way LOCAL_KB_EMBEDDING_MODEL already works. Importing it as a config constant would keep the old value until a restart. Show the current value of the settings that are not secrets. A model name rendered as ••••qwen3 gives no way to tell what is in effect, so the store now marks those keys (NON_SECRET_KEYS) and returns them unmasked; the API field is renamed masked -> display_value and carries a secret flag that the panel uses to pick the input type, replacing the list it kept on its own side. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from pydantic import BaseModel
|
|
from sqlalchemy.orm import Session as DBSession
|
|
|
|
from app.core import settings_store
|
|
from app.core.auth import require_settings_password
|
|
from app.db.database import get_db
|
|
|
|
router = APIRouter(prefix="/api/settings", tags=["settings"], dependencies=[Depends(require_settings_password)])
|
|
|
|
|
|
class SettingEntry(BaseModel):
|
|
key: str
|
|
is_set: bool
|
|
# 秘匿キーはマスク済みの値、それ以外は現在値そのもの。未設定なら None
|
|
display_value: str | None
|
|
# 入力欄をパスワード扱いにするか(APIキー等は True)
|
|
secret: bool
|
|
overridden: bool
|
|
|
|
|
|
class SaveSettingsRequest(BaseModel):
|
|
values: dict[str, str]
|
|
|
|
|
|
@router.get("", response_model=list[SettingEntry])
|
|
def list_settings(db: DBSession = Depends(get_db)):
|
|
return settings_store.list_masked(db)
|
|
|
|
|
|
@router.put("", response_model=list[SettingEntry])
|
|
def save_settings(req: SaveSettingsRequest, db: DBSession = Depends(get_db)):
|
|
try:
|
|
for key, value in req.values.items():
|
|
if not value:
|
|
continue # 空欄は「変更なし」として無視する
|
|
settings_store.save(db, key, value)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e)) from e
|
|
return settings_store.list_masked(db)
|
|
|
|
|
|
@router.delete("/{key}", response_model=list[SettingEntry])
|
|
def clear_setting(key: str, db: DBSession = Depends(get_db)):
|
|
try:
|
|
settings_store.clear(db, key)
|
|
except ValueError as e:
|
|
raise HTTPException(status_code=400, detail=str(e)) from e
|
|
return settings_store.list_masked(db)
|