fixed dalle3 command
This commit is contained in:
parent
299d8e677f
commit
13ae53cdad
2 changed files with 13 additions and 10 deletions
|
|
@ -21,14 +21,13 @@ class ChatGPT(commands.Cog):
|
||||||
self.remind_me_loop.start()
|
self.remind_me_loop.start()
|
||||||
self.http_session = self.create_aiohttp_session()
|
self.http_session = self.create_aiohttp_session()
|
||||||
self.logger = logging.getLogger("bot")
|
self.logger = logging.getLogger("bot")
|
||||||
|
self.headers = {
|
||||||
def create_aiohttp_session(self):
|
|
||||||
return aiohttp.ClientSession(
|
|
||||||
headers = {
|
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': f'Bearer {os.getenv("openai.api_key")}',
|
'Authorization': f'Bearer {os.getenv("openai.api_key")}',
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
def create_aiohttp_session(self):
|
||||||
|
return aiohttp.ClientSession()
|
||||||
|
|
||||||
def folder_setup(self):
|
def folder_setup(self):
|
||||||
try:
|
try:
|
||||||
|
|
@ -100,7 +99,7 @@ class ChatGPT(commands.Cog):
|
||||||
url = "https://api.openai.com/v1/chat/completions"
|
url = "https://api.openai.com/v1/chat/completions"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with self.http_session.post(url, json=data) as resp:
|
async with self.http_session.post(url, json=data, headers=self.headers) 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']
|
||||||
return response
|
return response
|
||||||
|
|
@ -212,7 +211,7 @@ class ChatGPT(commands.Cog):
|
||||||
url = "https://api.openai.com/v1/images/generations"
|
url = "https://api.openai.com/v1/images/generations"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with self.http_session.post(url, json=data) as resp:
|
async with self.http_session.post(url, json=data, headers=self.headers) as resp:
|
||||||
response_data = await resp.json()
|
response_data = await resp.json()
|
||||||
response = response_data['data'][0]['url']
|
response = response_data['data'][0]['url']
|
||||||
return response
|
return response
|
||||||
|
|
@ -295,7 +294,7 @@ class ChatGPT(commands.Cog):
|
||||||
url = "https://api.openai.com/v1/chat/completions"
|
url = "https://api.openai.com/v1/chat/completions"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with self.http_session.post(url, json=data) as resp:
|
async with self.http_session.post(url, json=data, headers=self.headers) as resp:
|
||||||
response_data = await resp.json()
|
response_data = await resp.json()
|
||||||
self.logger.debug(response_data)
|
self.logger.debug(response_data)
|
||||||
answer = response_data['choices'][0]['message']['content']
|
answer = response_data['choices'][0]['message']['content']
|
||||||
|
|
@ -402,7 +401,7 @@ class ChatGPT(commands.Cog):
|
||||||
url = "https://api.openai.com/v1/chat/completions"
|
url = "https://api.openai.com/v1/chat/completions"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with self.http_session.post(url, json=data) as resp:
|
async with self.http_session.post(url, json=data, headers=self.headers) as resp:
|
||||||
response_data = await resp.json()
|
response_data = await resp.json()
|
||||||
reaction = response_data['choices'][0]['message']['content'].strip()
|
reaction = response_data['choices'][0]['message']['content'].strip()
|
||||||
if is_emoji(reaction):
|
if is_emoji(reaction):
|
||||||
|
|
@ -425,7 +424,7 @@ class ChatGPT(commands.Cog):
|
||||||
url = "https://api.openai.com/v1/chat/completions"
|
url = "https://api.openai.com/v1/chat/completions"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with self.http_session.post(url, json=data) as resp:
|
async with self.http_session.post(url, json=data, headers=self.headers) 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']
|
||||||
if "Sparkytron 3000:" in response[0:17]:
|
if "Sparkytron 3000:" in response[0:17]:
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,10 @@ async def on_ready():
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_message(ctx):
|
async def on_message(ctx):
|
||||||
|
if ctx.channel.type == discord.ChannelType.private:
|
||||||
|
return
|
||||||
|
if ctx.author.bot:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
await bot.process_commands(ctx)
|
await bot.process_commands(ctx)
|
||||||
except commands.CommandNotFound:
|
except commands.CommandNotFound:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue