diff --git a/modules/ask/prompt.py b/modules/ask/prompt.py index 93d0c33d..68818a6f 100644 --- a/modules/ask/prompt.py +++ b/modules/ask/prompt.py @@ -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) """ diff --git a/modules/ask/tools/__init__.py b/modules/ask/tools/__init__.py index f2d6a0f7..ac6d1414 100644 --- a/modules/ask/tools/__init__.py +++ b/modules/ask/tools/__init__.py @@ -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] diff --git a/modules/ask/tools/bugtracker.py b/modules/ask/tools/bugtracker.py new file mode 100644 index 00000000..7b36322c --- /dev/null +++ b/modules/ask/tools/bugtracker.py @@ -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.' +) diff --git a/modules/ask/tools/random.py b/modules/ask/tools/random.py new file mode 100644 index 00000000..c5c961f3 --- /dev/null +++ b/modules/ask/tools/random.py @@ -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.' +) diff --git a/modules/ask/tools/utils.py b/modules/ask/tools/utils.py index 51ef18bb..c5cdb7ae 100644 --- a/modules/ask/tools/utils.py +++ b/modules/ask/tools/utils.py @@ -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):