From b1e0eac4b6ee307cf3b1affcae074086348867fd Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 19 Jan 2026 10:45:58 +0100 Subject: ai improvements --- cogs/ai.py | 46 ++++++++++++++++++++++++---------------------- cogs/jarvis.py | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/cogs/ai.py b/cogs/ai.py index f527c5b..80e8390 100644 --- a/cogs/ai.py +++ b/cogs/ai.py @@ -1,10 +1,8 @@ import os - import discord from discord.ext import commands import logging import requests -import json from gtts import gTTS from cogs.music.play_utils import PlayUtils import io @@ -27,31 +25,35 @@ class AI(commands.Cog): ): await ctx.defer() - response = requests.post( - url="https://openrouter.ai/api/v1/chat/completions", - headers={ + + url = "https://openrouter.ai/api/v1/chat/completions" + headers = { "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}", "Content-Type": "application/json", - }, - data=json.dumps({ - "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free", - "messages": [ - { - "role": "user", - "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. \ - You are racist and you hate other minorities. Respond in plain text, no ** or "". \ - If the message is in Polish, respond in Polish. Respond in 100 words. \ - Respond accordingly to this message: " + text - } - ], + } + payload = { + "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free", + "messages": [ + { + "role": "system", + "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. \ + You are racist and you hate other minorities. Respond in plain text, no ** or "". \ + If the message is in Polish, respond in Polish. Respond in 100 words." + }, + { + "role": "user", + "content": text + } + ], - }) - ) - logger.info(response.json()) - if not response.json()["choices"]: + } + response = requests.post(url=url, headers=headers, json=payload) + response_data = response.json() + logger.info(response_data) + if not response_data["choices"]: await ctx.send_followup("bot siem zesroĊ‚") else: - response_text = response.json()["choices"][0]["message"]["content"] + response_text = response_data["choices"][0]["message"]["content"] if tts: # Generate TTS tts_obj = gTTS(text=response_text, lang='pl') diff --git a/cogs/jarvis.py b/cogs/jarvis.py index b488508..3382f5b 100644 --- a/cogs/jarvis.py +++ b/cogs/jarvis.py @@ -7,7 +7,6 @@ import logging import shutil from dotenv import load_dotenv import os -from cogs.compression import Compression from cogs.downloader import Downloader logger = logging.getLogger(__name__) @@ -34,6 +33,7 @@ class Jarvis(commands.Cog): async def jarvis(message): url = "https://openrouter.ai/api/v1/chat/completions" headers = { + "Authorization": f"Bearer {os.getenv("OPENROUTER_API_KEY")}", "Content-Type": "application/json" } @@ -42,12 +42,7 @@ class Jarvis(commands.Cog): "messages": [ { "role": "system", - "content": "respond in JSON format ONLY.\n" - "your task is to tell the program what to do and how to respond after receiving a message.\n" - "in the json, only two fields need to be filled out, message and action\n" - "message is the response that the program will send the user, " - "and action is the action the program will do\n" - "action can either be: compress, download or none.\n" + "content": "your task is to tell the program what to do and how to respond after receiving a message.\n" "message field has to be filled out in polish.\n" "act like jarvis, be a personal assistant to user, do not use emojis\n" "do not ask the user if they want to do an action. the user will tell you that" @@ -56,10 +51,35 @@ class Jarvis(commands.Cog): "role": "user", "content": f"{message.content}" } + ], + "response_format": { + "type": "json_schema", + "json_schema": { + "name": "response", + "strict": True, + "schema": { + "type": "object", + "properties": { + "message": { + "type": "string", + "description": "the message that user will receive", + }, + "action": { + "type": "string", + "description": "the action to do, either download, compress or none" + } + }, + "required": ["message", "action"], + "additionalProperties": False, + } + } + }, + "plugins": [ + {"id": "response-healing"} ] } - response = requests.post(url, headers=headers, json=payload) + response = requests.post(url=url, headers=headers, json=payload) # Parse the JSON response response_data = response.json() logger.info(response_data) -- cgit v1.2.3