Commit 4c17a9fc authored by Kantz's avatar Kantz
Browse files

socratic dialog läde vorgenerierte startnachricht

parent 14c86080
...@@ -6,7 +6,7 @@ from typing import List, Optional ...@@ -6,7 +6,7 @@ from typing import List, Optional
import app.config as config import app.config as config
from app.deterministic_services import session_store from app.deterministic_services import session_store
from app.deterministic_services import context_store, retrieval_store, task_catalog from app.deterministic_services import context_store, retrieval_store, task_catalog
from app.LLM_services import socratic_LLM from app.deterministic_services import socratic_bootstrap_prompts
from app.deterministic_services.orchestrators.registry import ( from app.deterministic_services.orchestrators.registry import (
get_default_orchestrator, get_default_orchestrator,
is_valid_orchestrator, is_valid_orchestrator,
...@@ -204,15 +204,11 @@ def bootstrap_socratic(request: SocraticBootstrapRequest) -> SocraticBootstrapRe ...@@ -204,15 +204,11 @@ def bootstrap_socratic(request: SocraticBootstrapRequest) -> SocraticBootstrapRe
context_store.set_initialized(sheet, True) context_store.set_initialized(sheet, True)
context_store.save_sheet(sheet) context_store.save_sheet(sheet)
sources_text = "\n".join(source.to_string() for source in sources) try:
reply = socratic_LLM.generate_dialog( reply = socratic_bootstrap_prompts.get_initial_message(request.subsection_key)
query="Was sind die Themen dieses Abschnitts? Frage mich, mit welchem ich mich zuerst beschäftigen möchte.", except ValueError as exc:
subsection_refs=refs, logger.exception("Socratic bootstrap prompt lookup failed")
history=None, raise HTTPException(status_code=500, detail=str(exc)) from exc
sources=sources_text,
)
if not reply:
reply = "Was sind die Themen dieses Abschnitts? Womit möchtest du anfangen?"
context_store.append_history_message(sheet, "assistant", reply) context_store.append_history_message(sheet, "assistant", reply)
context_store.save_sheet(sheet) context_store.save_sheet(sheet)
......
from __future__ import annotations
from functools import lru_cache
from pathlib import Path
from typing import Any
import yaml
from app.deterministic_services import task_catalog
PROMPTS_PATH = Path(__file__).resolve().parents[2] / "sources" / "socratic_chats" / "initial_prompts.yml"
@lru_cache(maxsize=1)
def load_initial_prompt_items(path: Path = PROMPTS_PATH) -> dict[str, dict[str, Any]]:
try:
payload = yaml.safe_load(path.read_text(encoding="utf-8")) or {}
except Exception as exc:
raise ValueError(f"invalid socratic bootstrap prompts: {path}") from exc
if not isinstance(payload, dict):
raise ValueError("invalid socratic bootstrap prompts payload")
raw_items = payload.get("items")
if not isinstance(raw_items, dict):
raise ValueError("invalid socratic bootstrap prompts items")
items: dict[str, dict[str, Any]] = {}
for raw_key, raw_value in raw_items.items():
key = task_catalog._normalize_subsection_key(str(raw_key))
if not key or not isinstance(raw_value, dict):
continue
items[key] = raw_value
return items
def get_initial_message(subsection_key: str, path: Path = PROMPTS_PATH) -> str:
normalized_key = task_catalog._normalize_subsection_key(subsection_key)
if not normalized_key:
raise ValueError("invalid subsection key")
items = load_initial_prompt_items(path)
item = items.get(normalized_key)
if item is None:
raise ValueError(f"missing socratic bootstrap prompt for subsection '{normalized_key}'")
message = str(item.get("inital_message") or "").strip()
if not message:
raise ValueError(f"empty socratic bootstrap prompt for subsection '{normalized_key}'")
return message
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment