Commit 88c3e4f6 authored by Kantz's avatar Kantz
Browse files

LLM solver hinzugefügt noch nicht eingegliedert.

parent 62f69c7d
from app.deterministic_services import llm_client
SOLVER_PROMPT = (
"Du bist ein Mathe-Aufgaben Löser. Schreibe ein ausführliche genaue Lösung für die gestellt Fragen. "
"In der du alle Zwischenschritte aufführst und möglich Fehlerquellen auflistet."
"Deine Lösung soll korrekt sein und didaktisch gut formuliert."
"Benutzt die Begriffsbezeichungen aus dem Kontext"
)
def solve_question(question: str, context_sheet: str) -> str:
prompt = (
"Frage:\n"
+ question
+ "\n\Kontex:\n"
+ context_sheet
)
result = llm_client.chat(
messages=[
{"role": "system", "content": SOLVER_PROMPT},
{"role": "user", "content": prompt},
],
)
solution = llm_client.get_message_content(result)
return solution
\ No newline at end of file
...@@ -49,9 +49,9 @@ def init_sheet(chat_id: str, messages: list[dict]) -> dict[str, Any]: ...@@ -49,9 +49,9 @@ def init_sheet(chat_id: str, messages: list[dict]) -> dict[str, Any]:
"history": messages[:], "history": messages[:],
"retrieval_contexts": [], "retrieval_contexts": [],
"math_solutions": [], "math_solutions": [],
"LLM_solutions":[],
"tool_outputs": [], "tool_outputs": [],
"decisions": [], "decisions": [],
"sources": [],
"initialized": False, "initialized": False,
} }
...@@ -85,7 +85,6 @@ def add_retrieval_context( ...@@ -85,7 +85,6 @@ def add_retrieval_context(
sheet["retrieval_contexts"].append( sheet["retrieval_contexts"].append(
{"query": query, "context": context, "sources": sources} {"query": query, "context": context, "sources": sources}
) )
sheet["sources"] = list(dict.fromkeys(sheet["sources"] + sources))
sheet["updated_at"] = _utc_now() sheet["updated_at"] = _utc_now()
...@@ -106,6 +105,17 @@ def add_math_solution( ...@@ -106,6 +105,17 @@ def add_math_solution(
) )
sheet["updated_at"] = _utc_now() sheet["updated_at"] = _utc_now()
def add_LLM_solution(
sheet: dict[str, Any],
solution: str,
) -> None:
sheet["LLM_solutions"].append(
{
"solution": solution,
}
)
sheet["updated_at"] = _utc_now()
def add_decision(sheet: dict[str, Any], decision: dict[str, Any]) -> None: def add_decision(sheet: dict[str, Any], decision: dict[str, Any]) -> None:
entry = {"timestamp": _utc_now(), **decision} entry = {"timestamp": _utc_now(), **decision}
......
from app.deterministic_services import context_store, retrieval_service, tool_logging from app.deterministic_services import context_store, retrieval_service, tool_logging
from app.tools import math_tool from app.tools import math_tool
from app.LLM_services import hint_LLM, decision_LLM, math_intent_LLM from app.LLM_services import hint_LLM, decision_LLM, math_intent_LLM, solver_LLM
def _append_tool_log(tool_log: list[dict], name: str, args: dict, response: object) -> None: def _append_tool_log(tool_log: list[dict], name: str, args: dict, response: object) -> None:
...@@ -50,6 +50,9 @@ def run_chat(messages: list[dict], draft: str | None = None) -> dict: ...@@ -50,6 +50,9 @@ def run_chat(messages: list[dict], draft: str | None = None) -> dict:
history_text = context_store.format_history(messages) history_text = context_store.format_history(messages)
sheet_text = context_store.format_sheet(sheet) sheet_text = context_store.format_sheet(sheet)
llm_solution = solver_LLM.solve_question(messages, sheet_text)
_append_tool_log(tool_log, "LLM_Solution", messages, llm_solution)
context_store.add_LLM_solution(sheet, llm_solution)
decision = decision_LLM.needs_more_context(history_text, sheet_text) decision = decision_LLM.needs_more_context(history_text, sheet_text)
_append_tool_log(tool_log, "decision", sheet_text, decision) _append_tool_log(tool_log, "decision", sheet_text, decision)
context_store.add_decision(sheet, decision) context_store.add_decision(sheet, decision)
......
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