Slop Code
This commit is contained in:
parent
f1f27bb7e2
commit
73b487e3cb
@ -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),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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,6 +160,12 @@ 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)
|
||||||
|
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"])
|
_add_msg(app, "tool", str(result), tool_call_id=tc["id"])
|
||||||
else:
|
else:
|
||||||
if response.content:
|
if response.content:
|
||||||
|
|||||||
@ -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,6 +56,16 @@ 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)
|
||||||
|
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({
|
session.messages.append({
|
||||||
'role': 'tool',
|
'role': 'tool',
|
||||||
'tool_call_id': tc['id'],
|
'tool_call_id': tc['id'],
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user