We're working!
This commit is contained in:
@ -1,13 +1,30 @@
|
||||
import resource
|
||||
import subprocess
|
||||
import time
|
||||
import llm
|
||||
|
||||
TRICU_PATH = "/usr/local/bin/tricu"
|
||||
|
||||
def tricu-bridge(input: str) -> str:
|
||||
"""
|
||||
Description of tool goes here.
|
||||
"""
|
||||
return f"hello {input}"
|
||||
def tricubridge(input: str) -> str:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[TRICU_PATH, "eval", "+RTS", "-M250M", "-RTS"],
|
||||
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
|
||||
def register_tools(register):
|
||||
register(tricu-bridge)
|
||||
register(tricubridge)
|
||||
|
@ -1,5 +1,5 @@
|
||||
[project]
|
||||
name = "llm-tools-tricu-bridge"
|
||||
name = "llm-tools-tricubridge"
|
||||
version = "0.1"
|
||||
description = "A tool that allows running Tricu expressions"
|
||||
readme = "README.md"
|
||||
|
@ -1,7 +1,6 @@
|
||||
import llm
|
||||
import json
|
||||
from llm_tools_tricu_bridge import tricu-bridge
|
||||
|
||||
from llm_tools_tricu_bridge import tricubridge
|
||||
|
||||
def test_tool():
|
||||
model = llm.get_model("echo")
|
||||
@ -9,14 +8,14 @@ def test_tool():
|
||||
json.dumps(
|
||||
{
|
||||
"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())
|
||||
tool_results = json.loads(responses[-1].text())["tool_results"]
|
||||
assert tool_results == [
|
||||
{"name": "tricu-bridge", "output": "hello pelican", "tool_call_id": None}
|
||||
{"name": "tricubridge", "output": "t t", "tool_call_id": None}
|
||||
]
|
||||
|
Reference in New Issue
Block a user