Add tool examples

This commit is contained in:
oobabooga 2026-03-12 16:02:57 -03:00
parent a916fb0e5c
commit 2466305f76
3 changed files with 68 additions and 0 deletions

View file

@ -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")}

View file

@ -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)}

View file

@ -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."}]