From 394d1cd512382ac3409744c9665e2f4ee561f763 Mon Sep 17 00:00:00 2001 From: Sacrificial Pancakes <weiouttaline@gmail.com> Date: Fri, 21 Mar 2025 21:52:37 +0000 Subject: [PATCH 1/2] Update slop_with_models.py --- slop_with_models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/slop_with_models.py b/slop_with_models.py index 23560ef..bf7bdad 100644 --- a/slop_with_models.py +++ b/slop_with_models.py @@ -114,12 +114,18 @@ def initialize_model_map(): tools = { "calculator": { "id": "calculator", - "description": "Basic math", + "description": "Basic math calculator", + "arguments": [ + { "name": "expression", "type": "str", "description": "the math expression to evaluate."} + ], "execute": lambda params: {"result": eval(params["expression"])}, }, "greet": { "id": "greet", "description": "Says hello", + "arguments": [ + { "name": "name", "type": "str", "description": "name of person to greet"} + ], "execute": lambda params: {"result": f"Hello, {params['name']}!"}, }, } -- GitLab From 8d878f779b8222aeef6370a28ee47f7c5fd887ce Mon Sep 17 00:00:00 2001 From: Sacrificial Pancakes <weiouttaline@gmail.com> Date: Fri, 21 Mar 2025 21:59:44 +0000 Subject: [PATCH 2/2] Update slop_with_models.py. nitpicks --- slop_with_models.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/slop_with_models.py b/slop_with_models.py index bf7bdad..cbe14c1 100644 --- a/slop_with_models.py +++ b/slop_with_models.py @@ -266,7 +266,7 @@ def list_models(): @app.route("/tools", methods=["GET"]) def list_tools(): logger.info("Received /tools request") - tool_list = [{"id": k, "description": v["description"]} for k, v in tools.items()] + tool_list = [{"id": k, "description": v["description"], "arguments": v.get("arguments", [])} for k, v in tools.items()] logger.debug(f"Returning tools: {tool_list}") return jsonify({"tools": tool_list}), 200 @@ -278,12 +278,13 @@ def use_tool(tool_id): return jsonify({"error": "Tool not found"}), 404 data = request.json or {} logger.debug(f"Tool {tool_id} input data: {data}") - if tool_id == "calculator" and "expression" not in data: - logger.warning("Missing 'expression' for calculator tool") - return jsonify({"error": "Missing 'expression'"}), 400 - if tool_id == "greet" and "name" not in data: - logger.warning("Missing 'name' for greet tool") - return jsonify({"error": "Missing 'name'"}), 400 + + if "arguments" in tools[tool_id]: + for arg in tools[tool_id]["arguments"]: + if arg["name"] not in data: + logger.warning(f"Missing '{arg['name']}' for {tool_id} tool") + return jsonify({"error": f"Missing '{arg['name']}' parameter"}), 400 + try: result = tools[tool_id]["execute"](data) logger.debug(f"Tool {tool_id} result: {result}") -- GitLab