feat(prompts): implement TOML-backed prompt loading and refactor message generation

This commit is contained in:
Richie committed 2026-07-24 11:38:51 -04:00
1 parent 94f18722e4
commit 8073144e2b
7 files changed
+83 -24

No files matched your search

@@ -14,6 +14,7 @@ from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from python.ebook_search.llm_interface import request_chat_completion
from python.ebook_search.prompts import load_prompt
from python.ebook_search.protected_phrases.extraction import (
candidate_source_names,
get_sample_contexts,
@@ -369,20 +370,7 @@ def build_judge_messages(candidate: PhraseCandidate) -> list[dict[str, str]]:
"chapter_count": candidate.chapter_count,
"contexts": candidate.sample_contexts,
}
return [
{
"role": "system",
"content": (
"Judge whether a candidate phrase from a book should be protected for RAG retrieval. "
"Do not extract new phrases. Reject common grammar fragments, ordinary nonspecific phrases, "
"unstable fragments, and phrases kept only because they are frequent. Keep people, places, "
"organizations, factions, events, technologies, fictional conditions, magic systems, formal titles, "
"named concepts, and recurring world-specific terms. Return only a JSON object with keys: keep, "
"canonical, category, aliases, confidence, importance, allow_nested, suppress_children, reason."
),
},
{"role": "user", "content": json.dumps(payload, ensure_ascii=True)},
]
return load_prompt("phrase_judge").messages(candidate_json=json.dumps(payload, ensure_ascii=True))
def parse_llm_judgment(content: str, config: EbookSearchConfig) -> LLMJudgment: