This commit is contained in:
2025-02-18 22:33:26 +01:00
parent ca7f382d11
commit 027cddd886

View File

@@ -100,7 +100,8 @@ async def get_completion(message: str) -> str:
response = await client.post( response = await client.post(
"https://openrouter.ai/api/v1/chat/completions", "https://openrouter.ai/api/v1/chat/completions",
headers={ headers={
"Authorization": f"Bearer {config.OPENAI_API_KEY}" "Authorization": f"Bearer {config.OPENAI_API_KEY}",
"content-type": "application/json"
}, },
data={ data={
"model": "google/gemini-2.0-flash-thinking-exp:free", "model": "google/gemini-2.0-flash-thinking-exp:free",
@@ -140,6 +141,30 @@ class MessagesProc:
reply_parent_message_id=event.message_id reply_parent_message_id=event.message_id
) )
if event.message.text.lower().startswith("!ai"):
try:
completion = await get_completion(event.message.text)
max_length = 255
completion_parts = [completion[i:i + max_length] for i in range(0, len(completion), max_length)]
for part in completion_parts:
await twitch.send_chat_message(
event.broadcaster_user_id,
config.TWITCH_ADMIN_USER_ID,
part,
reply_parent_message_id=event.message_id
)
except Exception as e:
logger.error(f"Failed to get completion: {e}")
await twitch.send_chat_message(
event.broadcaster_user_id,
config.TWITCH_ADMIN_USER_ID,
"Ошибка!",
reply_parent_message_id=event.message_id
)
if event.chatter_user_login in cls.IGNORED_USER_LOGINS: if event.chatter_user_login in cls.IGNORED_USER_LOGINS:
return return