Commit da60296c authored by Kantz's avatar Kantz
Browse files

update von den Hint übergebenen parametern

parent 5832543c
......@@ -3,60 +3,34 @@ from app.deterministic_services import llm_client
def generate_hint(
task: str,
solution: str,
LLM_solution: str,
math_solution: str | None = None,
history: str | None = None,
retrival: str | None = None,
) -> str:
system_prompt = (
"Du bist ein didaktischer Tutor. "
"Gebe dem Nutzer hilfreiche Tipps um mathematische Aufgaben zu lösen. "
"Antworte nur mit dem Tipp, ohne weitere Erklärungen."
"Gibe keine komplette Lösung der Aufgabe."
"Die Mathematische Lösung hat immer Vorrang vor der LLM Lösung."
)
prompt = (
"Aufgabe:\n"
+ task
+ "\n\n"
"Loesung (vom Mathe-Tool):\n"
+ solution
"Loesung (von einem LLM):\n"
+ LLM_solution
+ "\n"
+ "Du bist ein didaktischer Tutor. "
"Schaue dir Aufgabe, die dazugehörige Lösung und die bisherige Historie an."
"Entscheide basierend darauf was der nächste Schritt ist den der Nutzer machen muss um zur Lösung zu kommne"
"Schreibe einen minimalen Tipp zum nächsten Schritt"
"Halte dich kurz und klar. Gibt nicht die Lösung aus."
)
if math_solution:
prompt += "Mathematische Loesung:\n" + math_solution + "\n"
if history:
prompt = "\nHistorie:\n" + history + "\n" + prompt
prompt += "\nHistorie:\n" + history + "\n"
if retrival:
prompt = "\nKontext:\n" + retrival + "\n" + prompt
result = llm_client.chat(
messages=[{"role": "user", "content": prompt}],
messages=[{"role": "system", "content": system_prompt}, {"role": "user", "content": prompt}],
)
return llm_client.get_message_content(result)
TOOL_SPEC = {
"type": "function",
"function": {
"name": "generate_hint",
"description": (
"Gibt einen didaktisch wertvollen naechsten Hinweis "
"auf Basis der Aufgabe und der berechneten Loesung."
),
"parameters": {
"type": "object",
"properties": {
"task": {"type": "string", "description": "Die gegebene Aufgabe"},
"solution": {
"type": "string",
"description": "Loesung aus dem Mathe-Tool",
},
"history": {
"type": "string",
"description": "Optionaler Verlauf, kann leer sein",
},
"retrival": {
"type": "string",
"description": "Optionales Kontextblatt mit Werkzeug- und Retrieval-Infos",
},
},
"required": ["task", "solution"],
},
},
}
return llm_client.get_message_content(result)
\ No newline at end of file
......@@ -138,6 +138,19 @@ def latest_math_solution(sheet: dict[str, Any]) -> str:
return ""
return sheet["math_solutions"][-1].get("solution", "")
def last_LLM_solution(sheet: dict[str, Any]) -> str:
if not sheet["LLM_solutions"]:
return ""
return sheet["LLM_solutions"][-1].get("solution", "")
def get_task(sheet: dict[str, Any]) -> str:
history = sheet.get("history", [])
if history:
return history[0].get("content", "")
return ""
def get_history(sheet: dict[str, Any]) -> str:
return format_history(sheet.get("history", []))
def first_math_solution(sheet: dict[str, Any]) -> str:
if not sheet["math_solutions"]:
......
......@@ -89,9 +89,10 @@ def run_chat(messages: list[dict], draft: str | None = None) -> dict:
# Hinweis und Ausgaben generierung
hint_args = {
"task": _extract_user_messages(messages)[0],
"solution": context_store.first_math_solution(sheet),
"history": history_text,
"task": context_store.get_task(sheet),
"LLM_solution": context_store.last_LLM_solution(sheet),
"math_solution": context_store.first_math_solution(sheet),
"history": context_store.format_history(messages),
"retrival": context_store.get_retrival(sheet),
}
reply = hint_LLM.generate_hint(**hint_args)
......
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