Skip to content

Commit b3955d5

Browse files
authored
feat(utils): add verbose logging and tools call command to gptme-util (#265)
- Add -v/--verbose flag for debug logging - Add 'tools call' command for direct tool function calls
1 parent 757bf1d commit b3955d5

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

gptme/util/cli.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
CLI for gptme utility commands.
33
"""
44

5+
import logging
56
import sys
67
from pathlib import Path
78

@@ -14,9 +15,12 @@
1415

1516

1617
@click.group()
17-
def main():
18+
@click.option("-v", "--verbose", is_flag=True, help="Enable verbose output.")
19+
def main(verbose: bool = False):
1820
"""Utility commands for gptme."""
19-
pass
21+
22+
if verbose:
23+
logging.getLogger().setLevel(logging.DEBUG)
2024

2125

2226
@main.group()
@@ -182,5 +186,51 @@ def tools_info(tool_name: str):
182186
print(tool.examples)
183187

184188

189+
@tools.command("call")
190+
@click.argument("tool_name")
191+
@click.argument("function_name")
192+
@click.option(
193+
"--arg",
194+
"-a",
195+
multiple=True,
196+
help="Arguments to pass to the function. Format: key=value",
197+
)
198+
def tools_call(tool_name: str, function_name: str, arg: list[str]):
199+
"""Call a tool with the given arguments."""
200+
from ..tools import get_tool, init_tools, loaded_tools # fmt: skip
201+
202+
# Initialize tools
203+
init_tools()
204+
205+
tool = get_tool(tool_name)
206+
if not tool:
207+
print(f"Tool '{tool_name}' not found. Available tools:")
208+
for t in loaded_tools:
209+
print(f"- {t.name}")
210+
sys.exit(1)
211+
212+
function = (
213+
[f for f in tool.functions if f.__name__ == function_name] or None
214+
if tool.functions
215+
else None
216+
)
217+
if not function:
218+
print(f"Function '{function_name}' not found in tool '{tool_name}'.")
219+
if tool.functions:
220+
print("Available functions:")
221+
for f in tool.functions:
222+
print(f"- {f.__name__}")
223+
else:
224+
print("No functions available for this tool.")
225+
sys.exit(1)
226+
else:
227+
# Parse arguments into a dictionary, ensuring proper typing
228+
kwargs = {}
229+
for arg_str in arg:
230+
key, value = arg_str.split("=", 1)
231+
kwargs[key] = value
232+
function[0](**kwargs)
233+
234+
185235
if __name__ == "__main__":
186236
main()

0 commit comments

Comments
 (0)