给ChatGPT装上手和脚,拿起工具提高你的生产力
chatgpt_tool_hub/tools/hello_tool
展示一个自定义tool的实现例子
git clone https://github.com/goldfishh/chatgpt-tool-hub.git
cd chatgpt-tool-hub
from typing import Any
from rich.console import Console
from chatgpt_tool_hub.tools.base_tool import BaseTool
default_tool_name = "your-tool-name"
class ExampleTool(BaseTool):
name = default_tool_name
description = (
"Introduce your tool to LLM and decide on which scenarios to use the tool."
)
def __init__(self, console: Console = Console(), **tool_kwargs: Any):
super().__init__(console=console)
def _run(self, query: str) -> str:
return "return string"
async def _arun(self, query: str) -> str:
"""Use the tool asynchronously."""
raise NotImplementedError("ExampleTool does not support async")
from chatgpt_tool_hub.tools.example_tool.tool import ExampleTool
from chatgpt_tool_hub.tools.all_tool_list import main_tool_register
main_tool_register.register_tool(default_tool_name,
lambda console, kwargs: ExampleTool(console, **kwargs),
tool_input_keys=[])
如果该tool必须要申请api-key,则api-key名称需要传入tool_input_keys中,用于检测kwargs是否传入api-key
{
"tools": ["your-tool-name"],
"kwargs": {
// ...
}
}
向llm提问,由llm判断是否使用该tool