aboutsummaryrefslogtreecommitdiffstats
path: root/cogs
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-01-19 10:45:58 +0100
committersalmonik <raisersoft@proton.me>2026-01-19 10:45:58 +0100
commitb1e0eac4b6ee307cf3b1affcae074086348867fd (patch)
tree7ce9c90060d5c76acef60dc4fe2f99583c63be4a /cogs
parentdo not expose the api key + prompt mod (diff)
downloadsenator-sperma-b1e0eac4b6ee307cf3b1affcae074086348867fd.tar.gz
senator-sperma-b1e0eac4b6ee307cf3b1affcae074086348867fd.zip
ai improvements
Diffstat (limited to 'cogs')
-rw-r--r--cogs/ai.py46
-rw-r--r--cogs/jarvis.py36
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 @@
1import os 1import os
2
3import discord 2import discord
4from discord.ext import commands 3from discord.ext import commands
5import logging 4import logging
6import requests 5import requests
7import json
8from gtts import gTTS 6from gtts import gTTS
9from cogs.music.play_utils import PlayUtils 7from cogs.music.play_utils import PlayUtils
10import io 8import io
@@ -27,31 +25,35 @@ class AI(commands.Cog):
27 ): 25 ):
28 await ctx.defer() 26 await ctx.defer()
29 27
30 response = requests.post( 28
31 url="https://openrouter.ai/api/v1/chat/completions", 29 url = "https://openrouter.ai/api/v1/chat/completions"
32 headers={ 30 headers = {
33 "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}", 31 "Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}",
34 "Content-Type": "application/json", 32 "Content-Type": "application/json",
35 }, 33 }
36 data=json.dumps({ 34 payload = {
37 "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free", 35 "model": "cognitivecomputations/dolphin-mistral-24b-venice-edition:free",
38 "messages": [ 36 "messages": [
39 { 37 {
40 "role": "user", 38 "role": "system",
41 "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. \ 39 "content": "You are Senator Steaven Sperma Armstrong from Metal Gear Rising Vengeance. \
42 You are racist and you hate other minorities. Respond in plain text, no ** or "". \ 40 You are racist and you hate other minorities. Respond in plain text, no ** or "". \
43 If the message is in Polish, respond in Polish. Respond in 100 words. \ 41 If the message is in Polish, respond in Polish. Respond in 100 words."
44 Respond accordingly to this message: " + text 42 },
45 } 43 {
46 ], 44 "role": "user",
45 "content": text
46 }
47 ],
47 48
48 }) 49 }
49 ) 50 response = requests.post(url=url, headers=headers, json=payload)
50 logger.info(response.json()) 51 response_data = response.json()
51 if not response.json()["choices"]: 52 logger.info(response_data)
53 if not response_data["choices"]:
52 await ctx.send_followup("bot siem zesroł") 54 await ctx.send_followup("bot siem zesroł")
53 else: 55 else:
54 response_text = response.json()["choices"][0]["message"]["content"] 56 response_text = response_data["choices"][0]["message"]["content"]
55 if tts: 57 if tts:
56 # Generate TTS 58 # Generate TTS
57 tts_obj = gTTS(text=response_text, lang='pl') 59 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
7import shutil 7import shutil
8from dotenv import load_dotenv 8from dotenv import load_dotenv
9import os 9import os
10from cogs.compression import Compression
11from cogs.downloader import Downloader 10from cogs.downloader import Downloader
12 11
13logger = logging.getLogger(__name__) 12logger = logging.getLogger(__name__)
@@ -34,6 +33,7 @@ class Jarvis(commands.Cog):
34 async def jarvis(message): 33 async def jarvis(message):
35 url = "https://openrouter.ai/api/v1/chat/completions" 34 url = "https://openrouter.ai/api/v1/chat/completions"
36 headers = { 35 headers = {
36
37 "Authorization": f"Bearer {os.getenv("OPENROUTER_API_KEY")}", 37 "Authorization": f"Bearer {os.getenv("OPENROUTER_API_KEY")}",
38 "Content-Type": "application/json" 38 "Content-Type": "application/json"
39 } 39 }
@@ -42,12 +42,7 @@ class Jarvis(commands.Cog):
42 "messages": [ 42 "messages": [
43 { 43 {
44 "role": "system", 44 "role": "system",
45 "content": "respond in JSON format ONLY.\n" 45 "content": "your task is to tell the program what to do and how to respond after receiving a message.\n"
46 "your task is to tell the program what to do and how to respond after receiving a message.\n"
47 "in the json, only two fields need to be filled out, message and action\n"
48 "message is the response that the program will send the user, "
49 "and action is the action the program will do\n"
50 "action can either be: compress, download or none.\n"
51 "message field has to be filled out in polish.\n" 46 "message field has to be filled out in polish.\n"
52 "act like jarvis, be a personal assistant to user, do not use emojis\n" 47 "act like jarvis, be a personal assistant to user, do not use emojis\n"
53 "do not ask the user if they want to do an action. the user will tell you that" 48 "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):
56 "role": "user", 51 "role": "user",
57 "content": f"{message.content}" 52 "content": f"{message.content}"
58 } 53 }
54 ],
55 "response_format": {
56 "type": "json_schema",
57 "json_schema": {
58 "name": "response",
59 "strict": True,
60 "schema": {
61 "type": "object",
62 "properties": {
63 "message": {
64 "type": "string",
65 "description": "the message that user will receive",
66 },
67 "action": {
68 "type": "string",
69 "description": "the action to do, either download, compress or none"
70 }
71 },
72 "required": ["message", "action"],
73 "additionalProperties": False,
74 }
75 }
76 },
77 "plugins": [
78 {"id": "response-healing"}
59 ] 79 ]
60 } 80 }
61 81
62 response = requests.post(url, headers=headers, json=payload) 82 response = requests.post(url=url, headers=headers, json=payload)
63 # Parse the JSON response 83 # Parse the JSON response
64 response_data = response.json() 84 response_data = response.json()
65 logger.info(response_data) 85 logger.info(response_data)