bot: Passthrough fuer vorformatierte Tool-Ergebnisse
Temperaturen/Energie/Heizung-Ausgaben werden direkt an den User weitergeleitet, ohne nochmal durch die LLM zu gehen. Behebt Umlaut-Verlust und Formatierungs-Aenderungen durch LLM.
This commit is contained in:
parent
91dc5d8261
commit
81f7bbff90
1 changed files with 15 additions and 1 deletions
|
|
@ -24,6 +24,8 @@ FALLBACK_MODEL = "qwen3:30b-a3b"
|
||||||
MAX_TOOL_ROUNDS = 3
|
MAX_TOOL_ROUNDS = 3
|
||||||
OLLAMA_MODELS = {VISION_MODEL, FALLBACK_MODEL}
|
OLLAMA_MODELS = {VISION_MODEL, FALLBACK_MODEL}
|
||||||
|
|
||||||
|
PASSTHROUGH_TOOLS = {"get_temperaturen", "get_energie", "get_heizung"}
|
||||||
|
|
||||||
import datetime as _dt
|
import datetime as _dt
|
||||||
_TODAY = _dt.date.today()
|
_TODAY = _dt.date.today()
|
||||||
_3M_AGO = (_TODAY - _dt.timedelta(days=90))
|
_3M_AGO = (_TODAY - _dt.timedelta(days=90))
|
||||||
|
|
@ -338,6 +340,8 @@ def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None) -
|
||||||
|
|
||||||
messages.append({"role": "user", "content": question})
|
messages.append({"role": "user", "content": question})
|
||||||
|
|
||||||
|
passthrough_result = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for _round in range(MAX_TOOL_ROUNDS):
|
for _round in range(MAX_TOOL_ROUNDS):
|
||||||
data = _call_openrouter(messages, api_key, use_tools=True)
|
data = _call_openrouter(messages, api_key, use_tools=True)
|
||||||
|
|
@ -347,6 +351,8 @@ def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None) -
|
||||||
tool_calls = msg.get("tool_calls")
|
tool_calls = msg.get("tool_calls")
|
||||||
if not tool_calls:
|
if not tool_calls:
|
||||||
content = msg.get("content") or ""
|
content = msg.get("content") or ""
|
||||||
|
if passthrough_result:
|
||||||
|
return passthrough_result
|
||||||
return content or "Keine Antwort vom LLM."
|
return content or "Keine Antwort vom LLM."
|
||||||
|
|
||||||
messages.append(msg)
|
messages.append(msg)
|
||||||
|
|
@ -368,12 +374,20 @@ def ask_with_tools(question: str, tool_handlers: dict, session_id: str = None) -
|
||||||
else:
|
else:
|
||||||
result = f"Unbekanntes Tool: {fn_name}"
|
result = f"Unbekanntes Tool: {fn_name}"
|
||||||
|
|
||||||
|
result_str = str(result)[:3000]
|
||||||
|
|
||||||
|
if fn_name in PASSTHROUGH_TOOLS and not result_str.startswith(("Fehler", "Keine")):
|
||||||
|
log.info("Passthrough-Tool %s: Ergebnis wird direkt weitergegeben", fn_name)
|
||||||
|
passthrough_result = result_str
|
||||||
|
|
||||||
messages.append({
|
messages.append({
|
||||||
"role": "tool",
|
"role": "tool",
|
||||||
"tool_call_id": tc["id"],
|
"tool_call_id": tc["id"],
|
||||||
"content": str(result)[:3000],
|
"content": result_str,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if passthrough_result:
|
||||||
|
return passthrough_result
|
||||||
data = _call_openrouter(messages, api_key, use_tools=False)
|
data = _call_openrouter(messages, api_key, use_tools=False)
|
||||||
return data["choices"][0]["message"]["content"]
|
return data["choices"][0]["message"]["content"]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue