mirror of
https://github.com/Hopiu/llm.git
synced 2026-04-30 01:44:44 +00:00
Fix the tests I broke in #1096
This commit is contained in:
parent
278509d824
commit
57459c0a6e
2 changed files with 52 additions and 27 deletions
|
|
@ -2500,7 +2500,7 @@ def tools_list(json_, python_tools):
|
|||
output_toolboxes = []
|
||||
tool_objects = []
|
||||
toolbox_objects = []
|
||||
for name, tool in tools.items():
|
||||
for name, tool in sorted(tools.items()):
|
||||
if isinstance(tool, Tool):
|
||||
tool_objects.append(tool)
|
||||
output_tools.append(
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import click
|
|||
import importlib
|
||||
import json
|
||||
import llm
|
||||
from llm.default_plugins.default_tools import llm_version
|
||||
from llm import cli, hookimpl, plugins, get_template_loaders, get_fragment_loaders
|
||||
import pathlib
|
||||
import textwrap
|
||||
|
|
@ -247,6 +248,13 @@ def test_register_tools(tmpdir, logs_db):
|
|||
implementation=count_character_in_word,
|
||||
plugin="ToolsPlugin",
|
||||
),
|
||||
"llm_version": llm.Tool(
|
||||
name="llm_version",
|
||||
description="Return the installed version of llm",
|
||||
input_schema={"properties": {}, "type": "object"},
|
||||
implementation=llm_version,
|
||||
plugin="llm.default_plugins.default_tools",
|
||||
),
|
||||
"output_as_json": llm.Tool(
|
||||
name="output_as_json",
|
||||
description=None,
|
||||
|
|
@ -264,27 +272,19 @@ def test_register_tools(tmpdir, logs_db):
|
|||
result = runner.invoke(cli.cli, ["tools", "list"])
|
||||
assert result.exit_code == 0
|
||||
assert result.output == (
|
||||
"upper(text: str) -> str (plugin: ToolsPlugin)\n\n"
|
||||
" Convert text to uppercase.\n\n"
|
||||
"count_chars(text: str, character: str) -> int (plugin: ToolsPlugin)\n\n"
|
||||
" Count the number of occurrences of a character in a word.\n\n"
|
||||
"llm_version() -> str (plugin: llm.default_plugins.default_tools)\n\n"
|
||||
" Return the installed version of llm\n\n"
|
||||
"output_as_json(text: str) (plugin: ToolsPlugin)\n\n"
|
||||
"upper(text: str) -> str (plugin: ToolsPlugin)\n\n"
|
||||
" Convert text to uppercase.\n\n"
|
||||
)
|
||||
# And --json
|
||||
result2 = runner.invoke(cli.cli, ["tools", "list", "--json"])
|
||||
assert result2.exit_code == 0
|
||||
assert json.loads(result2.output) == {
|
||||
"tools": [
|
||||
{
|
||||
"name": "upper",
|
||||
"description": "Convert text to uppercase.",
|
||||
"arguments": {
|
||||
"properties": {"text": {"type": "string"}},
|
||||
"required": ["text"],
|
||||
"type": "object",
|
||||
},
|
||||
"plugin": "ToolsPlugin",
|
||||
},
|
||||
{
|
||||
"name": "count_chars",
|
||||
"description": "Count the number of occurrences of a character in a word.",
|
||||
|
|
@ -298,6 +298,12 @@ def test_register_tools(tmpdir, logs_db):
|
|||
},
|
||||
"plugin": "ToolsPlugin",
|
||||
},
|
||||
{
|
||||
"name": "llm_version",
|
||||
"description": "Return the installed version of llm",
|
||||
"arguments": {"properties": {}, "type": "object"},
|
||||
"plugin": "llm.default_plugins.default_tools",
|
||||
},
|
||||
{
|
||||
"name": "output_as_json",
|
||||
"description": None,
|
||||
|
|
@ -308,9 +314,20 @@ def test_register_tools(tmpdir, logs_db):
|
|||
},
|
||||
"plugin": "ToolsPlugin",
|
||||
},
|
||||
{
|
||||
"name": "upper",
|
||||
"description": "Convert text to uppercase.",
|
||||
"arguments": {
|
||||
"properties": {"text": {"type": "string"}},
|
||||
"required": ["text"],
|
||||
"type": "object",
|
||||
},
|
||||
"plugin": "ToolsPlugin",
|
||||
},
|
||||
],
|
||||
"toolboxes": [],
|
||||
}
|
||||
|
||||
# And test the --tools option
|
||||
functions_path = str(tmpdir / "functions.py")
|
||||
with open(functions_path, "w") as fp:
|
||||
|
|
@ -472,7 +489,6 @@ def test_register_tools(tmpdir, logs_db):
|
|||
) in result6.output
|
||||
finally:
|
||||
plugins.pm.unregister(name="ToolsPlugin")
|
||||
assert llm.get_tools() == {}
|
||||
|
||||
|
||||
def test_register_toolbox(tmpdir, logs_db):
|
||||
|
|
@ -585,8 +601,25 @@ def test_register_toolbox(tmpdir, logs_db):
|
|||
result = runner.invoke(cli.cli, ["tools", "--json"])
|
||||
assert result.exit_code == 0
|
||||
assert json.loads(result.output) == {
|
||||
"tools": [],
|
||||
"tools": [
|
||||
{
|
||||
"name": "llm_version",
|
||||
"description": "Return the installed version of llm",
|
||||
"arguments": {"properties": {}, "type": "object"},
|
||||
"plugin": "llm.default_plugins.default_tools",
|
||||
}
|
||||
],
|
||||
"toolboxes": [
|
||||
{
|
||||
"name": "Filesystem",
|
||||
"tools": [
|
||||
{
|
||||
"name": "list_files",
|
||||
"description": None,
|
||||
"arguments": {"properties": {}, "type": "object"},
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Memory",
|
||||
"tools": [
|
||||
|
|
@ -630,16 +663,6 @@ def test_register_toolbox(tmpdir, logs_db):
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Filesystem",
|
||||
"tools": [
|
||||
{
|
||||
"name": "list_files",
|
||||
"description": None,
|
||||
"arguments": {"properties": {}, "type": "object"},
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
|
|
@ -647,6 +670,10 @@ def test_register_toolbox(tmpdir, logs_db):
|
|||
result = runner.invoke(cli.cli, ["tools"])
|
||||
assert result.exit_code == 0
|
||||
assert result.output == (
|
||||
"llm_version() -> str (plugin: llm.default_plugins.default_tools)\n\n"
|
||||
" Return the installed version of llm\n\n"
|
||||
"Filesystem:\n\n"
|
||||
" list_files()\n\n"
|
||||
"Memory:\n\n"
|
||||
" append(key: str, value: str)\n\n"
|
||||
" Append something as a key\n\n"
|
||||
|
|
@ -656,8 +683,6 @@ def test_register_toolbox(tmpdir, logs_db):
|
|||
" Return a list of keys\n\n"
|
||||
" set(key: str, value: str)\n\n"
|
||||
" Set something as a key\n\n"
|
||||
"Filesystem:\n\n"
|
||||
" list_files()\n\n"
|
||||
)
|
||||
|
||||
# Test the CLI running a toolbox prompt
|
||||
|
|
|
|||
Loading…
Reference in a new issue