From f92a20b2c58b024b529485da8be9a6eef24af664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Sat, 21 Oct 2023 10:24:07 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20change=20default=20typing=5Floop?= =?UTF-8?q?'s=20`sleep=5Ftime`=20to=2015=20seconds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nio_llm/client.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/nio_llm/client.py b/src/nio_llm/client.py index 7453437..f2823bb 100644 --- a/src/nio_llm/client.py +++ b/src/nio_llm/client.py @@ -77,12 +77,12 @@ class LLMClient(AsyncClient): async def typing_loop( self, - sleep_time: int = 10, + sleep_time: int = 15, ) -> None: """Send typing indicators every `sleep_time` seconds. Args: - sleep_time (`int`, default `10`): + sleep_time (`int`, default `15`): The time to sleep between sending typing indicators. """ logging.debug("Started typing indicator.") @@ -175,7 +175,7 @@ class LLMClient(AsyncClient): }, *[ { - "content": f"{message.sender}: {message.body}", + "content": f"<{message.sender}>: {message.body}", "role": "assistant" if message.sender == self.uid else "user", } for message in self.history @@ -187,19 +187,21 @@ class LLMClient(AsyncClient): logger.debug(f"Generated response: {response}") # retreive the response - output = response["choices"][0]["message"]["content"] # type: ignore - output = output.strip().removeprefix(f"{self.uid}:").strip() + output = response["choices"][0]["message"]["content"].strip() # type: ignore - # replace newlines with
- formatted_output = output.replace("\n", "
") + # strip the bot's uid from the response + output = output.removeprefix(f"<{self.uid}>:").strip() # detect mentions and replace them with html mentions formatted_output = re.sub( - r"@[^:]+:[^ :]+", + r"@[a-zA-Z-_]+:[^.]+\.[a-zA-Z]+", lambda match: f'', - formatted_output, + output, ) + # replace newlines with
+ formatted_output = formatted_output.replace("\n", "
") + logger.debug(f"Formatted response: {formatted_output}") # send the response