diff --git a/app.py b/app.py index ac05d59..5cfd9b4 100644 --- a/app.py +++ b/app.py @@ -70,30 +70,6 @@ LLM = Llama( print("Loaded model {model_path}".format(model_path=model_settings["model_path"])) - - - -class CommandExecutor: - async def process(command_list, text_input): - try: - text_input = re.sub(r"^[^\{]{1,}", "", text_input) - text_input = re.sub(r"[^\}]{1,}$", "", text_input) - json_blob = json.loads(text_input) - - if "command" in json_blob.keys(): - command_name = json_blob["command"] - if hasattr(command_list, command_name): - call_result = await getattr(command_list, command_name)(json_blob) - - if call_result is not None: - print(call_result) - except ValueError as x: - pass - except Exception as x: - print(x) - pass - - def get_response(text): global lock global model_settings @@ -182,11 +158,12 @@ async def on_message(msg): return messages = [] - msg_history = [message async for message in msg.channel.history(limit=50)] + msg_history = [message async for message in msg.channel.history(limit=10)] msg_history.reverse() for m in msg_history: + reference = None if m.reference is not None: reference = await get_message(msg.channel, m.reference.message_id) @@ -199,6 +176,7 @@ async def on_message(msg): if m.author.id == client.user.id: if reference is None or reference.author.id != msg.author.id: continue + now = datetime.datetime.now(datetime.timezone.utc) then = m.created_at @@ -283,46 +261,20 @@ async def on_message(msg): attention[session_name] = time.perf_counter() context = model_settings["default_context"] + if chl.topic is not None: context = chl.topic - if await y_or_n(context, "Does my previous message tell you to be forgetful?"): - while len(messages) > 1: - del messages[0] - - """ - if await y_or_n([messages[-1]], "Am I asking you to do something you don't know how to do?"): - if os.path.isfile("commands.py"): - import commands - importlib.reload(commands) - - command_list = commands.CommandList() - command_list.chl = chl - - context = "" - with open("commands.py") as f: - context = f.read() - - f_body = get_messages_as_text(context, [messages[-1]], for_completion=True) - f_resp = await get_response_wrapper(f_body) - - await CommandExecutor.process(command_list, f_resp) - return - """ - print(f"{user_name}: {msg.content}") print(f"{bot_name}: ", end="") - f_body = formatter.format(context, messages, for_completion=True) - f_resp = await get_response_wrapper(f_body) - print("") - - if await y_or_n([messages[-1]], "Did I just praise you?"): - praise = praise + 1 - await client.change_presence(activity=discord.CustomActivity(name=f"{praise} praises")) + async with chl.typing(): + f_body = formatter.format(context, messages, for_completion=True) + f_resp = await get_response_wrapper(f_body) await chl.send(f_resp, reference=msg) + #await chl.send(f_resp) if __name__ == "__main__": # Read the token: