自訂程式碼工具 - Hello World
此範例程式碼示範如何使用輔助功能來測試「自訂程式碼」工具。
Hello World 範例是最簡單的「自訂程式碼」工具。它定義了接受 name 參數並傳回 greeting 的單一工具類別。使用它作為您自己的工具的起點。
工具 _ 導入 .py
from aidputils.agents.tools.custom_tools.base import CustomToolBase
@BaseTool.register
class HelloTool(CustomToolBase):
"""A simple greeting tool."""
@classmethod
def _execute_tool(cls, conf, runtime_params, **context_vars):
name = runtime_params.get("name", "World")
return {"greeting": f"Hello, {name}!"}
工具 _config.json
{
"displayName": "Hello Tool",
"description": "A simple hello world tool",
"tools": [
{
"toolClassName": "HelloTool",
"displayName": "Hello Tool",
"description": "Returns a hello world greeting",
"version": "1.0.0",
"schema": [
{
"name": "name",
"type": "string",
"description": "Name to greet"
}
],
"conf": {}
}
]
}
要求 .txt
# no deps將這三個檔案封裝在 ZIP 封存檔的根目錄,然後透過套裝程序頁籤上傳 ZIP。上傳之後,請切換至參數頁籤,如果您想要覆寫預設值,請填入「描述」,然後切換至測試頁籤來呼叫工具。使用 name="Alice" 時,工具會傳回:
{"greeting": "Hello, Alice!"}