diff --git a/gptme/cli.py b/gptme/cli.py index 7bd5ed8b..ea1f287f 100644 --- a/gptme/cli.py +++ b/gptme/cli.py @@ -27,7 +27,7 @@ from .message import Message from .models import get_model from .prompts import get_prompt -from .tools import execute_msg, get_tool +from .tools import execute_msg, has_tool from .tools.browser import read_url from .util import epoch_to_age, generate_name @@ -578,7 +578,7 @@ def _parse_prompt(prompt: str) -> str | None: for path in paths: result += _parse_prompt(path) or "" - if get_tool("browser") is None: + if not has_tool("browser"): logger.warning("Browser tool not available, skipping URL read") else: for url in urls: diff --git a/gptme/tools/__init__.py b/gptme/tools/__init__.py index 91a31ca6..ae83ff63 100644 --- a/gptme/tools/__init__.py +++ b/gptme/tools/__init__.py @@ -1,7 +1,6 @@ import logging -from collections.abc import Generator +from collections.abc import Callable, Generator from dataclasses import dataclass -from collections.abc import Callable from xml.etree import ElementTree from ..message import Message @@ -210,3 +209,10 @@ def get_tool(tool_name: str) -> ToolSpec: if tool.name == tool_name: return tool raise ValueError(f"Tool '{tool_name}' not found") + + +def has_tool(tool_name: str) -> bool: + for tool in loaded_tools: + if tool.name == tool_name: + return True + return False