mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-03-18 03:14:39 +01:00
Add tool examples
This commit is contained in:
parent
a916fb0e5c
commit
2466305f76
18
user_data/tools/get_datetime.py
Normal file
18
user_data/tools/get_datetime.py
Normal 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")}
|
||||
23
user_data/tools/roll_dice.py
Normal file
23
user_data/tools/roll_dice.py
Normal 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)}
|
||||
27
user_data/tools/web_search.py
Normal file
27
user_data/tools/web_search.py
Normal 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."}]
|
||||
Loading…
Reference in a new issue