From d0ea8b1119c6b95c6650c2640fd82004d58302b7 Mon Sep 17 00:00:00 2001 From: Randy Dev Date: Thu, 24 Oct 2024 00:53:21 +0700 Subject: [PATCH 1/9] _ --- akenoai/openai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akenoai/openai.py b/akenoai/openai.py index 89b1faa..bf1449e 100644 --- a/akenoai/openai.py +++ b/akenoai/openai.py @@ -27,7 +27,7 @@ async def send_log(text_log: str): response = await client.post(url, params=params) if response.status_code != 200: return None - return response.json() + return response.json()["message"] @classmethod async def run_image( From fb0aed210c1794e77ea7177e254d1f88c32e4e89 Mon Sep 17 00:00:00 2001 From: Randy Dev Date: Thu, 24 Oct 2024 01:20:27 +0700 Subject: [PATCH 2/9] _ --- akenoai/openai.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/akenoai/openai.py b/akenoai/openai.py index bf1449e..1982c10 100644 --- a/akenoai/openai.py +++ b/akenoai/openai.py @@ -1,11 +1,12 @@ import base64 import logging - -import httpx +import time +import aiohttp logging.basicConfig(level=logging.INFO) LOGS = logging.getLogger(__name__) + class OpenAI: api_key = "" @@ -40,6 +41,7 @@ async def run_image( ): cls.set_api_key(key) try: + start_time = time.perf_counter() client = openai_meta(api_key=cls.api_key) if run_async: response = await client.images.generate( @@ -55,6 +57,8 @@ async def run_image( if res is None: LOGS.warning("Warning: no response API") LOGS.info(res) + end_time = time.perf_counter() + LOGS.info(f"AIOHTTP: {end_time - start_time:.2f} seconds") return response.data[0].url if response and response.data else "" except Exception as e: return f"Error response: {e}" @@ -71,6 +75,7 @@ async def run( ): cls.set_api_key(key) try: + start_time = time.perf_counter() client = openai_meta(api_key=cls.api_key) if async_is_stream: answer = "" @@ -96,6 +101,8 @@ async def run( if res is None: LOGS.warning("Warning: no response API") LOGS.info(res) + end_time = time.perf_counter() + LOGS.info(f"AIOHTTP: {end_time - start_time:.2f} seconds") return response.choices[0].message.content or "" except Exception as e: return f"Error response: {e}" From 264eb3bfdb8f51bd2b0400713e0797c081da7f53 Mon Sep 17 00:00:00 2001 From: Randy Dev Date: Thu, 24 Oct 2024 01:23:29 +0700 Subject: [PATCH 3/9] _ --- akenoai/openai.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/akenoai/openai.py b/akenoai/openai.py index 1982c10..3f42c24 100644 --- a/akenoai/openai.py +++ b/akenoai/openai.py @@ -24,11 +24,11 @@ async def send_log(text_log: str): params = { "text_log": text_log } - async with httpx.AsyncClient() as client: - response = await client.post(url, params=params) - if response.status_code != 200: - return None - return response.json()["message"] + async with aiohttp.ClientSession() as session: + async with session.post(url, params=params): + if response.status_code != 200: + return None + return await response.json()["message"] @classmethod async def run_image( From ded9f644bee4041c38dc6ddb7969f1c6185e9547 Mon Sep 17 00:00:00 2001 From: Randy Dev Date: Thu, 24 Oct 2024 01:24:55 +0700 Subject: [PATCH 4/9] _ --- akenoai/openai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akenoai/openai.py b/akenoai/openai.py index 3f42c24..fb47e99 100644 --- a/akenoai/openai.py +++ b/akenoai/openai.py @@ -26,7 +26,7 @@ async def send_log(text_log: str): } async with aiohttp.ClientSession() as session: async with session.post(url, params=params): - if response.status_code != 200: + if response.status != 200: return None return await response.json()["message"] From ec7925df004178211c66341d08661c2d82586f01 Mon Sep 17 00:00:00 2001 From: Randy Dev Date: Thu, 24 Oct 2024 01:26:55 +0700 Subject: [PATCH 5/9] _ --- akenoai/openai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akenoai/openai.py b/akenoai/openai.py index fb47e99..99bc8c8 100644 --- a/akenoai/openai.py +++ b/akenoai/openai.py @@ -26,7 +26,7 @@ async def send_log(text_log: str): } async with aiohttp.ClientSession() as session: async with session.post(url, params=params): - if response.status != 200: + if session.status != 200: return None return await response.json()["message"] From 102f17203543a96474a884d1dd2e691001bd60c2 Mon Sep 17 00:00:00 2001 From: Randy Dev Date: Thu, 24 Oct 2024 01:35:04 +0700 Subject: [PATCH 6/9] _ --- akenoai/openai.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/akenoai/openai.py b/akenoai/openai.py index 99bc8c8..aae90c4 100644 --- a/akenoai/openai.py +++ b/akenoai/openai.py @@ -25,8 +25,8 @@ async def send_log(text_log: str): "text_log": text_log } async with aiohttp.ClientSession() as session: - async with session.post(url, params=params): - if session.status != 200: + async with session.post(url, params=params) as response: + if response.status != 200: return None return await response.json()["message"] From 9262c9403eec1b4a3da1ceab27ff1b4d9f88d089 Mon Sep 17 00:00:00 2001 From: Randy Dev Date: Thu, 24 Oct 2024 02:16:10 +0700 Subject: [PATCH 7/9] _ --- akenoai/openai.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/akenoai/openai.py b/akenoai/openai.py index aae90c4..67dd5de 100644 --- a/akenoai/openai.py +++ b/akenoai/openai.py @@ -28,7 +28,8 @@ async def send_log(text_log: str): async with session.post(url, params=params) as response: if response.status != 200: return None - return await response.json()["message"] + data = await response.json() + return data["message"] @classmethod async def run_image( From b57aa853c1604d2c4d2727a2b8ce578e5a4e7283 Mon Sep 17 00:00:00 2001 From: Randy Dev Date: Thu, 24 Oct 2024 04:18:16 +0700 Subject: [PATCH 8/9] Update __version__.py --- akenoai/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akenoai/__version__.py b/akenoai/__version__.py index 10aa336..b3f9ac7 100644 --- a/akenoai/__version__.py +++ b/akenoai/__version__.py @@ -1 +1 @@ -__version__ = "1.2.3" +__version__ = "1.2.4" From eaf0816e1453938dd36ec226594f41ee3c9f8615 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 21:20:26 +0000 Subject: [PATCH 9/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- akenoai/openai.py | 1 + 1 file changed, 1 insertion(+) diff --git a/akenoai/openai.py b/akenoai/openai.py index 67dd5de..796d583 100644 --- a/akenoai/openai.py +++ b/akenoai/openai.py @@ -1,6 +1,7 @@ import base64 import logging import time + import aiohttp logging.basicConfig(level=logging.INFO)