File size: 1,016 Bytes
7edb85f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | from typing import Any, Callable
from tools.github_tool import (
search_github_repo,
search_github_repositories,
)
from tools.pypi_tool import search_pypi
from tools.stackoverflow_tool import search_stackoverflow
ToolFunction = Callable[..., dict[str, Any]]
TOOLS: dict[str, ToolFunction] = {
"search_pypi": search_pypi,
"search_github_repo": search_github_repo,
"search_github_repositories": (
search_github_repositories
),
"search_stackoverflow": search_stackoverflow,
}
def execute_tool(
name: str,
arguments: dict[str, Any],
) -> dict[str, Any]:
"""
Tool adını registry içerisinde bulur ve verilen
argümanlarla çalıştırır.
"""
tool = TOOLS.get(name)
if tool is None:
available_tools = ", ".join(
sorted(TOOLS.keys())
)
raise ValueError(
f"'{name}' adlı tool kayıtlı değil. "
f"Kullanılabilir tool'lar: {available_tools}"
)
return tool(**arguments) |