Slop Code

This commit is contained in:
Dita Aji Pratama 2026-07-24 19:07:09 +07:00
parent f1f27bb7e2
commit 73b487e3cb
4 changed files with 27 additions and 8 deletions

View File

@ -44,6 +44,7 @@ for prov in _providers:
"base_url" : base_url,
"api_key" : api_key,
"default" : is_default,
"vision" : m.get("vision", False),
})

View File

@ -3,6 +3,7 @@ import threading
from datetime import datetime
import config
from lib import ntro, agent_loop
from tools.vision import ImagePayload
def _add_msg(app, role, content, **kwargs):
@ -159,6 +160,12 @@ def _agent_loop(app):
}))
app.scroll = 999999
result = agent_loop.execute_tool(tc, app.TOOL_HANDLERS)
if isinstance(result, ImagePayload):
_add_msg(app, "tool", [
{"type": "text", "text": f"[Image loaded: {result.path}]"},
{"type": "image_url", "image_url": {"url": f"data:{result.mime};base64,{result.data}"}}
], tool_call_id=tc["id"])
else:
_add_msg(app, "tool", str(result), tool_call_id=tc["id"])
else:
if response.content:

View File

@ -1,5 +1,6 @@
import json
from datetime import datetime
from tools.vision import ImagePayload
def _ts():
return datetime.now().strftime('%H:%M:%S')
@ -55,6 +56,16 @@ def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on
if tc['function']['name'] == 'end_session':
session_ended = True
result = execute_tool(tc, TOOL_HANDLERS)
if isinstance(result, ImagePayload):
session.messages.append({
'role': 'tool',
'tool_call_id': tc['id'],
'content': [
{"type": "text", "text": f"[Image loaded: {result.path}]"},
{"type": "image_url", "image_url": {"url": f"data:{result.mime};base64,{result.data}"}}
]
})
else:
session.messages.append({
'role': 'tool',
'tool_call_id': tc['id'],

View File

@ -10,8 +10,8 @@ def tool_schemas(tools_definition):
def tool_handlers(tools_definition):
return {t["name"]: t["handler"] for t in tools_definition}
def strip_thinking(text: str) -> str:
if not text:
def strip_thinking(text):
if not text or not isinstance(text, str):
return text
# Strip XML-style thinking blocks (case-insensitive, DOTALL for multiline)
text = re.sub(r'<think[^>]*>.*?</think>', '', text, flags=re.DOTALL | re.IGNORECASE)