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, "base_url" : base_url,
"api_key" : api_key, "api_key" : api_key,
"default" : is_default, "default" : is_default,
"vision" : m.get("vision", False),
}) })

View File

@ -3,6 +3,7 @@ import threading
from datetime import datetime from datetime import datetime
import config import config
from lib import ntro, agent_loop from lib import ntro, agent_loop
from tools.vision import ImagePayload
def _add_msg(app, role, content, **kwargs): def _add_msg(app, role, content, **kwargs):
@ -159,7 +160,13 @@ def _agent_loop(app):
})) }))
app.scroll = 999999 app.scroll = 999999
result = agent_loop.execute_tool(tc, app.TOOL_HANDLERS) result = agent_loop.execute_tool(tc, app.TOOL_HANDLERS)
_add_msg(app, "tool", str(result), tool_call_id=tc["id"]) 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: else:
if response.content: if response.content:
_add_msg(app, "assistant", response.content) _add_msg(app, "assistant", response.content)

View File

@ -1,5 +1,6 @@
import json import json
from datetime import datetime from datetime import datetime
from tools.vision import ImagePayload
def _ts(): def _ts():
return datetime.now().strftime('%H:%M:%S') return datetime.now().strftime('%H:%M:%S')
@ -55,11 +56,21 @@ def run_agent_loop(session, llm_client, TOOLS, TOOL_HANDLERS, max_iterations, on
if tc['function']['name'] == 'end_session': if tc['function']['name'] == 'end_session':
session_ended = True session_ended = True
result = execute_tool(tc, TOOL_HANDLERS) result = execute_tool(tc, TOOL_HANDLERS)
session.messages.append({ if isinstance(result, ImagePayload):
'role': 'tool', session.messages.append({
'tool_call_id': tc['id'], 'role': 'tool',
'content': str(result), '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'],
'content': str(result),
})
else: else:
if response.content: if response.content:
print(f'[{_ts()}] Response generated ({len(response.content)} chars)', flush=True) print(f'[{_ts()}] Response generated ({len(response.content)} chars)', flush=True)

View File

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