From 2466305f76a7c197178096021eb3f18e0449410a Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Thu, 12 Mar 2026 16:02:57 -0300 Subject: [PATCH] Add tool examples --- user_data/tools/get_datetime.py | 18 ++++++++++++++++++ user_data/tools/roll_dice.py | 23 +++++++++++++++++++++++ user_data/tools/web_search.py | 27 +++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 user_data/tools/get_datetime.py create mode 100644 user_data/tools/roll_dice.py create mode 100644 user_data/tools/web_search.py diff --git a/user_data/tools/get_datetime.py b/user_data/tools/get_datetime.py new file mode 100644 index 00000000..f0a92777 --- /dev/null +++ b/user_data/tools/get_datetime.py @@ -0,0 +1,18 @@ +from datetime import datetime + +tool = { + "type": "function", + "function": { + "name": "get_datetime", + "description": "Get the current date and time.", + "parameters": { + "type": "object", + "properties": {}, + } + } +} + + +def execute(arguments): + now = datetime.now() + return {"date": now.strftime("%Y-%m-%d"), "time": now.strftime("%I:%M %p")} diff --git a/user_data/tools/roll_dice.py b/user_data/tools/roll_dice.py new file mode 100644 index 00000000..9cab48a8 --- /dev/null +++ b/user_data/tools/roll_dice.py @@ -0,0 +1,23 @@ +import random + +tool = { + "type": "function", + "function": { + "name": "roll_dice", + "description": "Roll one or more dice with the specified number of sides.", + "parameters": { + "type": "object", + "properties": { + "count": {"type": "integer", "description": "Number of dice to roll.", "default": 1}, + "sides": {"type": "integer", "description": "Number of sides per die.", "default": 20}, + }, + } + } +} + + +def execute(arguments): + count = arguments.get("count", 1) + sides = arguments.get("sides", 20) + rolls = [random.randint(1, sides) for _ in range(count)] + return {"rolls": rolls, "total": sum(rolls)} diff --git a/user_data/tools/web_search.py b/user_data/tools/web_search.py new file mode 100644 index 00000000..8923eab0 --- /dev/null +++ b/user_data/tools/web_search.py @@ -0,0 +1,27 @@ +from modules.web_search import perform_web_search + +tool = { + "type": "function", + "function": { + "name": "web_search", + "description": "Search the web using DuckDuckGo and return page contents.", + "parameters": { + "type": "object", + "properties": { + "query": {"type": "string", "description": "The search query."}, + }, + "required": ["query"] + } + } +} + + +def execute(arguments): + query = arguments.get("query", "") + results = perform_web_search(query, num_pages=3) + output = [] + for r in results: + if r and r["content"].strip(): + output.append({"title": r["title"], "url": r["url"], "content": r["content"][:4000]}) + + return output if output else [{"error": "No results found."}]