removed commented out lines and unused aiohttp sessions/unused modules

This commit is contained in:
phixxy 2024-01-21 00:56:36 -08:00
parent 20a63ab637
commit 3adc73beaf

View file

@ -2,8 +2,6 @@
import os import os
import time import time
import json import json
from PIL import Image, PngImagePlugin
import aiohttp
from discord.ext import commands, tasks from discord.ext import commands, tasks
class AsyncOpenAI(commands.Cog): class AsyncOpenAI(commands.Cog):
@ -28,7 +26,6 @@ class AsyncOpenAI(commands.Cog):
def read_db(self,filepath): def read_db(self,filepath):
with open(filepath,"r") as fileobj: with open(filepath,"r") as fileobj:
db_content = json.load(fileobj) db_content = json.load(fileobj)
#print(db_content,type(db_content))
return db_content return db_content
def save_to_db(self,filepath,db_content): def save_to_db(self,filepath,db_content):
@ -62,11 +59,9 @@ class AsyncOpenAI(commands.Cog):
url = "https://api.openai.com/v1/chat/completions" url = "https://api.openai.com/v1/chat/completions"
try: try:
http_session = aiohttp.ClientSession() async with self.bot.http_session.post(url, headers=headers, json=data) as resp:
async with http_session.post(url, headers=headers, json=data) as resp:
response_data = await resp.json() response_data = await resp.json()
response = response_data['choices'][0]['message']['content'] response = response_data['choices'][0]['message']['content']
await http_session.close()
return response return response
except Exception as error: except Exception as error:
@ -135,12 +130,10 @@ class AsyncOpenAI(commands.Cog):
url = "https://api.openai.com/v1/chat/completions" url = "https://api.openai.com/v1/chat/completions"
try: try:
http_session = aiohttp.ClientSession() async with self.bot.http_session.post(url, headers=headers, json=data) as resp:
async with http_session.post(url, headers=headers, json=data) as resp:
response_data = await resp.json() response_data = await resp.json()
print(response_data) print(response_data)
answer = response_data['choices'][0]['message']['content'] answer = response_data['choices'][0]['message']['content']
await http_session.close()
except Exception as error: except Exception as error:
@ -208,18 +201,6 @@ class AsyncOpenAI(commands.Cog):
print("Fulfilled reminders successfully purged") print("Fulfilled reminders successfully purged")
self.save_to_db(reminders_path,data) self.save_to_db(reminders_path,data)
# def read_db(filepath):
# with open(filepath,"r") as fileobj:
# db_content = json.load(fileobj)
# #print(db_content,type(db_content))
# return db_content
# def save_to_db(filepath,db_content):
# with open(filepath,"w") as fileobj:
# json.dump(db_content,fileobj,indent=4)
async def setup(bot): async def setup(bot):
await bot.add_cog(AsyncOpenAI(bot)) await bot.add_cog(AsyncOpenAI(bot))