diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aca2a1..8b4dd40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,20 @@ # Jainy Bot Changelog -## Version v1.1.0 +## Version v1.1.1 -**Features** +**Fixes** -- Added dalle command to generate images via ai +- Fixed synchronous code blocking discord health check **Dev Deps** +- removed requests lib for aiohttp to handle async requests + +## Version v1.1.0 +**Features** +- Added dalle command to generate images via ai + +**Dev Deps** - added requests for api calls ## Version v1.0.0 diff --git a/jainy_bot/commands/dalle.py b/jainy_bot/commands/dalle.py index 7901c6d..72329a6 100644 --- a/jainy_bot/commands/dalle.py +++ b/jainy_bot/commands/dalle.py @@ -1,14 +1,26 @@ import base64 from io import BytesIO +import aiohttp import discord -import requests from discord.ext import commands from loguru import logger from config import DALLE_API_URL +async def make_api_request(payload: dict) -> dict or None: + async with aiohttp.ClientSession() as session: + async with session.post(DALLE_API_URL, json=payload) as response: + if response.status == 200: + logger.info(f'Successfully contacted Dalle Api') + payload = await response.json() + return payload + else: + logger.error(f'Dalle Server responded with status = {response.status}') + return None + + class Dalle(commands.Cog, name="Dalle"): def __init__(self, bot: commands.bot): self.bot = bot @@ -23,12 +35,12 @@ async def dalle(self, ctx: commands.Context, prompt: str): } await ctx.send(f'{ctx.author.mention} hang tight I\'m checking with Dall-E') - response = requests.post(DALLE_API_URL, json=payload) + response = await make_api_request(payload) - if response.status_code == 200: + if response: logger.info(f"Dalle image created successfully") await ctx.send(f'{ctx.author.mention} generating image please wait') - data = response.json() + data = response images = data['images'] files = [] @@ -43,6 +55,4 @@ async def dalle(self, ctx: commands.Context, prompt: str): embed=discord.Embed(title=f'{prompt} requested by {ctx.author}') ) else: - logger.error( - f'Error creating a Dalle image with prompt: {prompt} server responded with status = {response.status_code}') await ctx.send('Could not generate images') diff --git a/requirements.txt b/requirements.txt index 2400404..b970d70 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,18 @@ +aiohttp==3.9.4 +aiosignal==1.3.1 +anyio==4.3.0 +attrs==23.2.0 +certifi==2024.2.2 +charset-normalizer==3.3.2 discord==2.3.2 +discord.py==2.3.2 +frozenlist==1.4.1 +h11==0.14.0 +httpcore==1.0.5 +httpx==0.27.0 +idna==3.7 loguru==0.7.2 -requests~=2.31.0 +multidict==6.0.5 +sniffio==1.3.1 +urllib3==2.2.1 +yarl==1.9.4