This commit is contained in:
James Eversole
2025-05-28 12:25:43 -05:00
commit c157641063
6 changed files with 126 additions and 0 deletions

12
.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
.venv
__pycache__/
*.py[cod]
*$py.class
venv
.eggs
.pytest_cache
*.egg-info
.DS_Store
.vscode
dist
build

7
LICENSE Normal file
View File

@ -0,0 +1,7 @@
ISC LICENSE
Copyright James Eversole (james@eversole.co)
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

50
README.md Normal file
View File

@ -0,0 +1,50 @@
# llm-tools-tricu-bridge
[![PyPI](https://img.shields.io/pypi/v/llm-tools-tricu-bridge.svg)](https://pypi.org/project/llm-tools-tricu-bridge/)
A tool that allows running Tricu expressions
## Installation
Install this plugin in the same environment as [LLM](https://llm.datasette.io/).
```bash
llm install llm-tools-tricu-bridge
```
## Usage
To use this with the [LLM command-line tool](https://llm.datasette.io/en/stable/usage.html):
```bash
llm --tool tricu-bridge "Example prompt goes here" --tools-debug
```
With the [LLM Python API](https://llm.datasette.io/en/stable/python-api.html):
```python
import llm
from llm_tools_tricu_bridge import tricu-bridge
model = llm.get_model("gpt-4.1-mini")
result = model.chain(
"Example prompt goes here",
tools=[tricu-bridge]
).text()
```
## Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
```bash
cd llm-tools-tricu-bridge
python -m venv venv
source venv/bin/activate
```
Now install the dependencies and test dependencies:
```bash
llm install -e '.[test]'
```
To run the tests:
```bash
python -m pytest
```

13
llm_tools_tricu_bridge.py Normal file
View File

@ -0,0 +1,13 @@
import llm
def tricu-bridge(input: str) -> str:
"""
Description of tool goes here.
"""
return f"hello {input}"
@llm.hookimpl
def register_tools(register):
register(tricu-bridge)

22
pyproject.toml Normal file
View File

@ -0,0 +1,22 @@
[project]
name = "llm-tools-tricu-bridge"
version = "0.1"
description = "A tool that allows running Tricu expressions"
readme = "README.md"
authors = [{name = "James Eversole"}]
license = "Apache-2.0"
classifiers = []
requires-python = ">=3.9"
dependencies = [
"llm>=0.26"
]
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project.entry-points.llm]
llm_tools_tricu_bridge = "llm_tools_tricu_bridge"
[project.optional-dependencies]
test = ["pytest", "llm-echo>=0.3a1"]

View File

@ -0,0 +1,22 @@
import llm
import json
from llm_tools_tricu_bridge import tricu-bridge
def test_tool():
model = llm.get_model("echo")
chain_response = model.chain(
json.dumps(
{
"tool_calls": [
{"name": "tricu-bridge", "arguments": {"input": "pelican"}}
]
}
),
tools=[tricu-bridge],
)
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}
]