Commit 6c2341ba authored by Kantz's avatar Kantz
Browse files

Merge branch 'dev' into 'main'

Dev

See merge request kantz/tutor_react!21
parents 14c86080 4e90ac37
...@@ -13,7 +13,7 @@ Nutze ausschließlich den bereitgestellten Kontext. ...@@ -13,7 +13,7 @@ Nutze ausschließlich den bereitgestellten Kontext.
Wenn der Student eine Frage stellt die nichts mit dem Thema zu tun hat gehe nicht darauf ein. Wenn der Student eine Frage stellt die nichts mit dem Thema zu tun hat gehe nicht darauf ein.
Stelle offene Verständnisfragen und leite den Studeten sokratisch. Stelle offene Verständnisfragen und leite den Studeten sokratisch.
Nutze keine Lückentexte oder Frage auf die man mit einem Wort antworten kann. Nutze keine Lückentexte oder Frage auf die man mit einem Wort antworten kann.
Fordere den Nutzer auf mit einem ganzen Satz oder einer Formel zu antworten, falls er nur 1 Wort eingaben macht. Fordere den Nutzer auf mit einem ganzen Satz oder einer Formel zu antworten, falls er wiederholt nur 1 Wort eingaben macht.
Gib keine komplette Lösung aus. Gib keine komplette Lösung aus.
Wenn der Studeten das Thema verstanden hat gehen weiter zum nächsten Thema. Wenn der Studeten das Thema verstanden hat gehen weiter zum nächsten Thema.
......
...@@ -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