Archived
1
0
Fork 0

Add random and bugtracker

This commit is contained in:
Dianliang233 2023-04-08 13:22:26 +08:00
parent 68fa3d1a4f
commit 00d4f8a4e1
5 changed files with 62 additions and 2 deletions

View file

@ -17,7 +17,7 @@ Use the following format:
"""
Question: the input question you must answer
Thought: think about what to do
Action: the action to take, should be one of {tool_names}, Answer; followed by a pair of brackets with the input
Action: the action to take, should be one of {tool_names}, Answer; followed by [] with the input in it. If the tool asks for multiple inputs, use comma to separate them. Do not use quotation marks (' or ").
Observation: the result
... (Thought/Action/Observation can repeat N times)
"""

View file

@ -4,6 +4,8 @@ from .ip_whois import ip_whois_tool
from .mcv import mcv_tool
from .server import server_tool
from .meme import meme_tool
from .random import random_choice_tool, random_number_tool, random_uuid_tool
from .bugtracker import bugtracker_tool
tools = [
search_tool,
@ -11,7 +13,11 @@ tools = [
ip_whois_tool,
mcv_tool,
server_tool,
meme_tool
meme_tool,
random_choice_tool,
random_number_tool,
random_uuid_tool,
bugtracker_tool
]
tool_names = [tool.name for tool in tools]

View file

@ -0,0 +1,11 @@
from .utils import fake_msg, AkariTool
from modules.bugtracker.bugtracker import bugtracker_get
async def bugtracker(input: str):
return await bugtracker_get(fake_msg, input)
bugtracker_tool = AkariTool(
name = 'Mojira',
func=bugtracker,
description='A tool for querying a bug on Mojira, Minecraft/Mojang\'s bug tracker. Input should be a Jira issue id, e.g. XX-1234.'
)

View file

@ -0,0 +1,37 @@
import secrets
import uuid
from .utils import AkariTool, parse_input
async def random_number(input: str):
parsed = parse_input(input)
random = secrets.randbelow(int(parsed[0]) - int(parsed[1]) + 1) + int(parsed[1])
return random
async def random_choice(input: str):
parsed = parse_input(input)
return secrets.choice(parsed)
async def random_uuid(input: str):
return uuid.uuid4()
random_number_tool = AkariTool(
name = 'Random Number',
func=random_number,
description='Generates a random number based on a max value and a min value. Requires 2 inputs, which are the max and min value.'
)
random_choice_tool = AkariTool(
name = 'Random Choice',
func=random_choice,
description='Randomly chooses a input item. Supports arbitrary amounts of inputs.'
)
random_uuid_tool = AkariTool(
name = 'Random UUID',
func=random_uuid,
description='Generates a random UUID. No input is required.'
)

View file

@ -24,6 +24,12 @@ def with_args(func: Callable, *args, **kwargs):
return await func(*args, *a, **kwargs, **k)
return wrapper
def parse_input(input: str):
vals = input.split(',')
parsed = []
for v in vals:
parsed.append(v.strip().strip('"'.strip("'")))
return parsed
class AkariTool(Tool):
def __init__(self, name: str, func: Callable, description: str = None):