Update slop_with_models.py #1
1 changed files with 15 additions and 8 deletions
|
|
@ -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']}!"},
|
||||
},
|
||||
}
|
||||
|
|
@ -260,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
|
||||
|
||||
|
|
@ -272,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}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue