Slop Code
This commit is contained in:
parent
f1f27bb7e2
commit
73b487e3cb
@ -44,6 +44,7 @@ for prov in _providers:
|
||||
"base_url" : base_url,
|
||||
"api_key" : api_key,
|
||||
"default" : is_default,
|
||||
"vision" : m.get("vision", False),
|
||||
})
|
||||
|
||||
|
||||
|
||||
@ -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,7 +160,13 @@ def _agent_loop(app):
|
||||
}))
|
||||
app.scroll = 999999
|
||||
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:
|
||||
if response.content:
|
||||
_add_msg(app, "assistant", response.content)
|
||||
|
||||
@ -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,11 +56,21 @@ 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)
|
||||
session.messages.append({
|
||||
'role': 'tool',
|
||||
'tool_call_id': tc['id'],
|
||||
'content': str(result),
|
||||
})
|
||||
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'],
|
||||
'content': str(result),
|
||||
})
|
||||
else:
|
||||
if response.content:
|
||||
print(f'[{_ts()}] Response generated ({len(response.content)} chars)', flush=True)
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user