Download backend/app/api/tools.py from Rixhot/ZARAI: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/Rixhot/ZARAI/resolve/main/backend/app/api/tools.py
- Command line
-
hf download hf://spaces/Rixhot/ZARAI/backend/app/api/tools.py
-
curl -L -o tools.py https://huggingface.co/spaces/Rixhot/ZARAI/resolve/main/backend/app/api/tools.py
1.8 kB
| """ | |
| JARVIS — Tools API Route | |
| POST /api/tools/execute — run a tool directly | |
| GET /api/tools/list — list available tools | |
| """ | |
| from fastapi import APIRouter, HTTPException | |
| from pydantic import BaseModel | |
| from typing import Optional, Any | |
| from app.tools.tool_executor import execute_tool, TOOL_DEFINITIONS | |
| router = APIRouter() | |
| class ToolRequest(BaseModel): | |
| tool_name: str | |
| argument: str | |
| class Config: | |
| json_schema_extra = { | |
| "example": { | |
| "tool_name": "calculator", | |
| "argument": "sqrt(144) + 2**8", | |
| } | |
| } | |
| class ToolResponse(BaseModel): | |
| success: bool | |
| result: str | |
| tool: str | |
| argument: str | |
| value: Optional[Any] = None | |
| async def execute_tool_endpoint(request: ToolRequest): | |
| """Execute a named tool with an argument.""" | |
| if request.tool_name not in TOOL_DEFINITIONS: | |
| raise HTTPException( | |
| status_code=400, | |
| detail=f"Unknown tool '{request.tool_name}'. Available: {list(TOOL_DEFINITIONS.keys())}", | |
| ) | |
| result = execute_tool(request.tool_name, request.argument) | |
| return ToolResponse( | |
| success=result.get("success", False), | |
| result=result.get("result", ""), | |
| tool=result.get("tool", request.tool_name), | |
| argument=result.get("argument", request.argument), | |
| value=result.get("value"), | |
| ) | |
| async def list_tools(): | |
| """List all available tools with descriptions.""" | |
| return { | |
| "tools": [ | |
| { | |
| "name": t["name"], | |
| "description": t["description"], | |
| "example": t["example"], | |
| } | |
| for t in TOOL_DEFINITIONS.values() | |
| ] | |
| } | |