(request: ToolRequest, func=tool_func)
| 41 | for tool_name, tool_func in registry.tools.items(): |
| 42 | # 创建动态的POST endpoint |
| 43 | async def create_tool_endpoint(request: ToolRequest, func=tool_func): |
| 44 | try: |
| 45 | # 检查必需参数 |
| 46 | sig = inspect.signature(func) |
| 47 | required_params = { |
| 48 | name for name, param in sig.parameters.items() |
| 49 | if param.default == inspect.Parameter.empty |
| 50 | } |
| 51 | |
| 52 | # 验证是否提供了所有必需参数 |
| 53 | if not all(param in request.args for param in required_params): |
| 54 | missing = required_params - request.args.keys() |
| 55 | raise HTTPException( |
| 56 | status_code=400, |
| 57 | detail=f"Missing required parameters: {missing}" |
| 58 | ) |
| 59 | |
| 60 | result = func(**request.args) |
| 61 | return {"status": "success", "result": result} |
| 62 | except Exception as e: |
| 63 | raise HTTPException(status_code=400, detail=str(e)) |
| 64 | |
| 65 | # 添加endpoint到FastAPI应用 |
| 66 | endpoint = create_tool_endpoint |
nothing calls this directly
no outgoing calls
no test coverage detected