Skip to content

Commit

Permalink
fix: fixed bug checking for browser tool when not available
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Sep 5, 2024
1 parent 780b3c8 commit f86569d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gptme/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions gptme/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit f86569d

Please sign in to comment.