update
This commit is contained in:
@@ -16,6 +16,7 @@ from config import (
|
||||
MODEL_GUIDE,
|
||||
MODEL_BAUSTEIN_GEN,
|
||||
MODEL_BAUSTEIN_REWORK,
|
||||
MODEL_CHAT,
|
||||
STORAGE_DIR,
|
||||
)
|
||||
from database import (
|
||||
@@ -556,6 +557,48 @@ def _build_topic_suggest_prompt(problem: str, existing_topics: list[str]) -> str
|
||||
return template.replace("{problem}", problem).replace("{existing}", existing)
|
||||
|
||||
|
||||
def _build_guide_chat_prompt(topic: str, format_name: str, section: str, outline: str, messages: list[dict]) -> str:
|
||||
transcript = "\n".join(
|
||||
f"{'Nutzer' if m.get('role') == 'user' else 'Assistent'}: {m.get('content', '')}"
|
||||
for m in messages
|
||||
)
|
||||
outline_block = outline.strip() or "(keine)"
|
||||
section_block = section.strip() or "(kein Abschnitt erkannt)"
|
||||
return f"""Du bist ein hilfreicher Tutor zum Lern-Guide "{topic}" (Format: {format_name}). Ein Leser stellt dir Fragen, während er den Guide liest.
|
||||
|
||||
GLIEDERUNG DES GUIDES:
|
||||
{outline_block}
|
||||
|
||||
AKTUELLER ABSCHNITT, DEN DER LESER GERADE LIEST:
|
||||
{section_block}
|
||||
|
||||
BISHERIGER CHAT-VERLAUF:
|
||||
{transcript}
|
||||
|
||||
Antworte als Assistent auf die letzte Nutzer-Nachricht.
|
||||
|
||||
WICHTIG – Antwortstil:
|
||||
- KURZ und EINFACH: 1–3 Sätze, klare Sprache.
|
||||
- Keine Einleitung, keine Wiederholung der Frage, kein Markdown-Drumherum.
|
||||
- Beantworte nur die Frage; nutze den Abschnitt und die Gliederung als Kontext.
|
||||
|
||||
Gib NUR die Antwort aus, kein Präfix wie "Assistent:"."""
|
||||
|
||||
|
||||
async def chat_with_guide(topic: str, format_name: str, section: str, outline: str, messages: list[dict]) -> str:
|
||||
try:
|
||||
prompt = _build_guide_chat_prompt(topic, format_name, section, outline, messages)
|
||||
returncode, stdout, stderr = await _run_claude(
|
||||
"chat-" + str(uuid.uuid4()), prompt, 120, tools=None, model=MODEL_CHAT
|
||||
)
|
||||
if returncode != 0:
|
||||
return "Entschuldigung, das hat nicht geklappt. Bitte versuche es erneut."
|
||||
reply = stdout.strip()
|
||||
return reply or "Entschuldigung, ich habe keine Antwort erhalten."
|
||||
except Exception:
|
||||
return "Entschuldigung, das hat nicht geklappt. Bitte versuche es erneut."
|
||||
|
||||
|
||||
async def suggest_topics(problem: str, existing_topics: list[str] | None = None) -> list[dict]:
|
||||
try:
|
||||
prompt = _build_topic_suggest_prompt(problem, existing_topics or [])
|
||||
|
||||
Reference in New Issue
Block a user