Merge branch 'sacrificialpancakes-main-patch-33603' into 'main'
Update slop_with_models.py See merge request engineering/unturf/slop.unturf.com!1
This commit is contained in:
commit
e63fe48e41
1 changed files with 15 additions and 8 deletions
|
|
@ -114,12 +114,18 @@ def initialize_model_map():
|
||||||
tools = {
|
tools = {
|
||||||
"calculator": {
|
"calculator": {
|
||||||
"id": "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"])},
|
"execute": lambda params: {"result": eval(params["expression"])},
|
||||||
},
|
},
|
||||||
"greet": {
|
"greet": {
|
||||||
"id": "greet",
|
"id": "greet",
|
||||||
"description": "Says hello",
|
"description": "Says hello",
|
||||||
|
"arguments": [
|
||||||
|
{ "name": "name", "type": "str", "description": "name of person to greet"}
|
||||||
|
],
|
||||||
"execute": lambda params: {"result": f"Hello, {params['name']}!"},
|
"execute": lambda params: {"result": f"Hello, {params['name']}!"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -260,7 +266,7 @@ def list_models():
|
||||||
@app.route("/tools", methods=["GET"])
|
@app.route("/tools", methods=["GET"])
|
||||||
def list_tools():
|
def list_tools():
|
||||||
logger.info("Received /tools request")
|
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}")
|
logger.debug(f"Returning tools: {tool_list}")
|
||||||
return jsonify({"tools": tool_list}), 200
|
return jsonify({"tools": tool_list}), 200
|
||||||
|
|
||||||
|
|
@ -272,12 +278,13 @@ def use_tool(tool_id):
|
||||||
return jsonify({"error": "Tool not found"}), 404
|
return jsonify({"error": "Tool not found"}), 404
|
||||||
data = request.json or {}
|
data = request.json or {}
|
||||||
logger.debug(f"Tool {tool_id} input data: {data}")
|
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")
|
if "arguments" in tools[tool_id]:
|
||||||
return jsonify({"error": "Missing 'expression'"}), 400
|
for arg in tools[tool_id]["arguments"]:
|
||||||
if tool_id == "greet" and "name" not in data:
|
if arg["name"] not in data:
|
||||||
logger.warning("Missing 'name' for greet tool")
|
logger.warning(f"Missing '{arg['name']}' for {tool_id} tool")
|
||||||
return jsonify({"error": "Missing 'name'"}), 400
|
return jsonify({"error": f"Missing '{arg['name']}' parameter"}), 400
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = tools[tool_id]["execute"](data)
|
result = tools[tool_id]["execute"](data)
|
||||||
logger.debug(f"Tool {tool_id} result: {result}")
|
logger.debug(f"Tool {tool_id} result: {result}")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue