We're working!

This commit is contained in:
James Eversole
2025-05-28 12:34:43 -05:00
parent c157641063
commit 720ed05912
3 changed files with 28 additions and 12 deletions

View File

@ -1,13 +1,30 @@
import resource
import subprocess
import time
import llm import llm
TRICU_PATH = "/usr/local/bin/tricu"
def tricu-bridge(input: str) -> str: def tricubridge(input: str) -> str:
""" try:
Description of tool goes here. result = subprocess.run(
""" [TRICU_PATH, "eval", "+RTS", "-M250M", "-RTS"],
return f"hello {input}" input=input,
capture_output=True,
text=True,
check=True,
)
if len(result.stdout) > 2000:
return "Output too large; limited to 2000 chars."
else:
return result.stdout.strip()
except subprocess.CalledProcessError as e:
return f"Error executing Tricu code: {e.stderr or str(e)}"
except Exception as e:
return f"Unexpected error: {str(e)}"
@llm.hookimpl @llm.hookimpl
def register_tools(register): def register_tools(register):
register(tricu-bridge) register(tricubridge)

View File

@ -1,5 +1,5 @@
[project] [project]
name = "llm-tools-tricu-bridge" name = "llm-tools-tricubridge"
version = "0.1" version = "0.1"
description = "A tool that allows running Tricu expressions" description = "A tool that allows running Tricu expressions"
readme = "README.md" readme = "README.md"

View File

@ -1,7 +1,6 @@
import llm import llm
import json import json
from llm_tools_tricu_bridge import tricu-bridge from llm_tools_tricu_bridge import tricubridge
def test_tool(): def test_tool():
model = llm.get_model("echo") model = llm.get_model("echo")
@ -9,14 +8,14 @@ def test_tool():
json.dumps( json.dumps(
{ {
"tool_calls": [ "tool_calls": [
{"name": "tricu-bridge", "arguments": {"input": "pelican"}} {"name": "tricubridge", "arguments": {"input": "x = t t"}}
] ]
} }
), ),
tools=[tricu-bridge], tools=[tricubridge],
) )
responses = list(chain_response.responses()) responses = list(chain_response.responses())
tool_results = json.loads(responses[-1].text())["tool_results"] tool_results = json.loads(responses[-1].text())["tool_results"]
assert tool_results == [ assert tool_results == [
{"name": "tricu-bridge", "output": "hello pelican", "tool_call_id": None} {"name": "tricubridge", "output": "t t", "tool_call_id": None}
] ]