mirror of
https://github.com/Laurent2916/nio-llm.git
synced 2024-10-23 01:56:21 +00:00
Compare commits
No commits in common. "95c751ea303364f523204eed06d8fb650710582c" and "8dac964d2d8dea5ff16ec4190ebb1fbea648a235" have entirely different histories.
95c751ea30
...
8dac964d2d
|
@ -77,12 +77,12 @@ class LLMClient(AsyncClient):
|
||||||
|
|
||||||
async def typing_loop(
|
async def typing_loop(
|
||||||
self,
|
self,
|
||||||
sleep_time: int = 15,
|
sleep_time: int = 10,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Send typing indicators every `sleep_time` seconds.
|
"""Send typing indicators every `sleep_time` seconds.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
sleep_time (`int`, default `15`):
|
sleep_time (`int`, default `10`):
|
||||||
The time to sleep between sending typing indicators.
|
The time to sleep between sending typing indicators.
|
||||||
"""
|
"""
|
||||||
logging.debug("Started typing indicator.")
|
logging.debug("Started typing indicator.")
|
||||||
|
@ -108,7 +108,6 @@ class LLMClient(AsyncClient):
|
||||||
event (`RoomMessageText`):
|
event (`RoomMessageText`):
|
||||||
The message event.
|
The message event.
|
||||||
"""
|
"""
|
||||||
try:
|
|
||||||
logger.debug(f"New RoomMessageText: {event.source}")
|
logger.debug(f"New RoomMessageText: {event.source}")
|
||||||
|
|
||||||
# ignore messages pre-dating our spawn time
|
# ignore messages pre-dating our spawn time
|
||||||
|
@ -176,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",
|
"role": "assistant" if message.sender == self.uid else "user",
|
||||||
}
|
}
|
||||||
for message in self.history
|
for message in self.history
|
||||||
|
@ -188,21 +187,19 @@ class LLMClient(AsyncClient):
|
||||||
logger.debug(f"Generated response: {response}")
|
logger.debug(f"Generated response: {response}")
|
||||||
|
|
||||||
# retreive the response
|
# retreive the response
|
||||||
output = response["choices"][0]["message"]["content"].strip() # type: ignore
|
output = response["choices"][0]["message"]["content"] # type: ignore
|
||||||
|
output = output.strip().removeprefix(f"{self.uid}:").strip()
|
||||||
|
|
||||||
# strip the bot's uid from the response
|
# replace newlines with <br>
|
||||||
output = output.removeprefix(f"<{self.uid}>:").strip()
|
formatted_output = output.replace("\n", "<br>")
|
||||||
|
|
||||||
# detect mentions and replace them with html mentions
|
# detect mentions and replace them with html mentions
|
||||||
formatted_output = re.sub(
|
formatted_output = re.sub(
|
||||||
r"@[a-zA-Z-_]+:[^.]+\.[a-zA-Z]+",
|
r"@[^:]+:[^ :]+",
|
||||||
lambda match: f'<a href="https://matrix.to/#/{match.group(0)}"></a>',
|
lambda match: f'<a href="https://matrix.to/#/{match.group(0)}"></a>',
|
||||||
output,
|
formatted_output,
|
||||||
)
|
)
|
||||||
|
|
||||||
# replace newlines with <br>
|
|
||||||
formatted_output = formatted_output.replace("\n", "<br>")
|
|
||||||
|
|
||||||
logger.debug(f"Formatted response: {formatted_output}")
|
logger.debug(f"Formatted response: {formatted_output}")
|
||||||
|
|
||||||
# send the response
|
# send the response
|
||||||
|
@ -220,8 +217,6 @@ class LLMClient(AsyncClient):
|
||||||
|
|
||||||
# stop typing indicator loop
|
# stop typing indicator loop
|
||||||
typing_task.cancel()
|
typing_task.cancel()
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Exception in message_callback: {e}")
|
|
||||||
|
|
||||||
async def start(
|
async def start(
|
||||||
self,
|
self,
|
||||||
|
|
Loading…
Reference in a new issue