From e33d53d554af386201e0c6b353e50b0aaa2d1943 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Tue, 18 Feb 2025 23:01:00 +0100 Subject: [PATCH] Update --- .../stream_notifications/messages_proc.py | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/modules/stream_notifications/messages_proc.py b/src/modules/stream_notifications/messages_proc.py index 09631b3..1a9b9db 100644 --- a/src/modules/stream_notifications/messages_proc.py +++ b/src/modules/stream_notifications/messages_proc.py @@ -93,9 +93,27 @@ class MessageEvent(BaseModel): -async def get_completion(message: str) -> str: +async def get_completion(message: str, reply_to: str | None = None) -> str: logger.info(f"Getting completion for message: {message}") + messages = [ + { + "role": "system", + "content": "Don't use markdown! Don't use blocked words on Twitch! Make answers short and clear!" + } + ] + + if reply_to: + messages.append({ + "role": "assistant", + "content": reply_to + }) + + messages.append({ + "role": "user", + "content": message + }) + async with AsyncClient() as client: response = await client.post( "https://openrouter.ai/api/v1/chat/completions", @@ -105,16 +123,7 @@ async def get_completion(message: str) -> str: }, json={ "model": "google/gemini-2.0-flash-thinking-exp:free", - "messages": [ - { - "role": "system", - "content": "Don't use markdown! Don't use blocked words on Twitch! Make answers short and clear!" - }, - { - "role": "user", - "content": message - } - ] + "messages": messages } ) @@ -147,7 +156,7 @@ class MessagesProc: if event.message.text.lower().startswith("!ai"): try: - completion = await get_completion(event.message.text) + completion = await get_completion(event.message.text.replace("!ai", "").strip()) max_length = 255 completion_parts = [completion[i:i + max_length] for i in range(0, len(completion), max_length)]