simplify search tool and enable configuration for search engine

This commit is contained in:
Hardik Shah 2024-09-09 18:41:11 -07:00
parent 640c5f8ab9
commit bdede6d14e
6 changed files with 56 additions and 48 deletions

View file

@ -15,10 +15,9 @@ from llama_toolchain.memory.api import Memory
from llama_toolchain.safety.api import Safety
from llama_toolchain.agentic_system.api import * # noqa: F403
from llama_toolchain.tools.builtin import (
BraveSearchTool,
CodeInterpreterTool,
PhotogenTool,
RemoteSearchTool,
SearchTool,
WolframAlphaTool,
)
from llama_toolchain.tools.safety import with_safety
@ -63,20 +62,19 @@ class MetaReferenceAgenticSystemImpl(AgenticSystem):
if not key:
raise ValueError("Wolfram API key not defined in config")
tool = WolframAlphaTool(key)
elif isinstance(tool_defn, BraveSearchToolDefinition):
if tool_defn.remote_execution is not None:
tool = RemoteSearchTool(tool_defn.remote_execution)
else:
elif isinstance(tool_defn, SearchToolDefinition):
key = None
if tool_defn.engine == SearchEngineType.brave:
key = self.config.brave_search_api_key
if not key:
raise ValueError("Brave API key not defined in config")
tool = BraveSearchTool(key)
elif tool_defn.engine == SearchEngineType.bing:
key = self.config.bing_search_api_key
if not key:
raise ValueError("API key not defined in config")
tool = SearchTool(tool_defn.engine, key)
elif isinstance(tool_defn, CodeInterpreterToolDefinition):
tool = CodeInterpreterTool()
elif isinstance(tool_defn, PhotogenToolDefinition):
tool = PhotogenTool(
dump_dir=tempfile.mkdtemp(),
)
tool = PhotogenTool(dump_dir=tempfile.mkdtemp())
else:
continue