Set the search summary model from the settings panel
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>
This commit is contained in:
@@ -29,6 +29,7 @@ TAVILY_API_KEY: str | None = os.getenv("TAVILY_API_KEY")
|
||||
# 蓄積した知識をシステムプロンプトに注入する際の最大件数
|
||||
KNOWLEDGE_CONTEXT_LIMIT: int = int(os.getenv("KNOWLEDGE_CONTEXT_LIMIT", "15"))
|
||||
# Web検索結果を構造的な要約にまとめる際に使うモデル(未設定ならDEFAULT_MODELを使用)
|
||||
# GUI設定画面から実行時に変更できるため、実際の参照は memory_kb/knowledge._summary_model() が os.environ から行う。
|
||||
SEARCH_SUMMARY_MODEL: str | None = os.getenv("SEARCH_SUMMARY_MODEL")
|
||||
|
||||
# ローカルMarkdownナレッジベース(話題に応じて関連ファイルをシステムプロンプトに注入)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
import httpx
|
||||
@@ -10,7 +11,6 @@ from app.core import llm
|
||||
from app.core.config import (
|
||||
KNOWLEDGE_CONTEXT_LIMIT,
|
||||
KNOWLEDGE_TOOL_CONTENT_LIMIT,
|
||||
SEARCH_SUMMARY_MODEL,
|
||||
)
|
||||
from app.core.memory_kb import local_knowledge
|
||||
from app.db.models import KnowledgeEntry, KnowledgeSource
|
||||
@@ -37,6 +37,14 @@ _SUMMARY_PROMPT = (
|
||||
_HEADLINE_MARKERS = ("要約:", "要約:")
|
||||
|
||||
|
||||
def _summary_model() -> str | None:
|
||||
"""GUIの設定画面から実行時に変更できるよう、起動時定数ではなく都度 os.environ を見に行く。
|
||||
|
||||
未設定(空文字含む)なら None を返し、llm.complete() 側で DEFAULT_MODEL にフォールバックさせる。
|
||||
"""
|
||||
return os.environ.get("SEARCH_SUMMARY_MODEL") or None
|
||||
|
||||
|
||||
def _split_headline(text: str) -> tuple[str, str]:
|
||||
"""LLMの出力を (一行要約, 本文) に分ける。1行目が想定の形式でなければ見出しは空で返す。"""
|
||||
lines = text.strip().splitlines()
|
||||
@@ -87,7 +95,7 @@ async def summarize_results(query: str, results: list[dict], model: str | None =
|
||||
try:
|
||||
text = await llm.complete(
|
||||
[{"role": "user", "content": prompt}],
|
||||
model=model or SEARCH_SUMMARY_MODEL,
|
||||
model=model or _summary_model(),
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Failed to summarize search results for query=%r", query)
|
||||
|
||||
@@ -16,8 +16,18 @@ CONFIGURABLE_KEYS = [
|
||||
"OLLAMA_API_BASE",
|
||||
"TAVILY_API_KEY",
|
||||
"LOCAL_KB_EMBEDDING_MODEL",
|
||||
"SEARCH_SUMMARY_MODEL",
|
||||
]
|
||||
|
||||
# 秘匿情報ではないキー。値をマスクせずそのまま返し、GUIでも通常のテキスト入力として扱う。
|
||||
# モデル名やURLは「今どれが効いているか」が見えないと設定しづらいため。
|
||||
NON_SECRET_KEYS = {
|
||||
"AWS_REGION_NAME",
|
||||
"OLLAMA_API_BASE",
|
||||
"LOCAL_KB_EMBEDDING_MODEL",
|
||||
"SEARCH_SUMMARY_MODEL",
|
||||
}
|
||||
|
||||
# .env由来の起動時の値のスナップショット。clear() で戻す先として使う。
|
||||
_env_defaults: dict[str, str | None] = {}
|
||||
_snapshot_taken = False
|
||||
@@ -47,15 +57,18 @@ def load_into_env(db: DBSession) -> None:
|
||||
|
||||
|
||||
def list_masked(db: DBSession) -> list[dict]:
|
||||
"""GUI設定画面に出す一覧。秘匿キーの値はマスクし、そうでないキーは現在値をそのまま見せる。"""
|
||||
_ensure_snapshot()
|
||||
saved = {row.key: row.value for row in db.query(AppSetting).all()}
|
||||
result = []
|
||||
for key in CONFIGURABLE_KEYS:
|
||||
current = os.environ.get(key)
|
||||
secret = key not in NON_SECRET_KEYS
|
||||
result.append({
|
||||
"key": key,
|
||||
"is_set": bool(current),
|
||||
"masked": _mask(current) if current else None,
|
||||
"display_value": (_mask(current) if secret else current) if current else None,
|
||||
"secret": secret,
|
||||
"overridden": key in saved,
|
||||
})
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user