switch from request to aiohttp

This commit is contained in:
Philipp 2024-04-07 22:31:48 +02:00
parent 3c0b9664ff
commit 5473df0e5d
Signed by: Spaenny
GPG Key ID: 9EBD8439AFBAB750
2 changed files with 24 additions and 25 deletions

View File

@ -1,10 +1,9 @@
import json
import urllib
import requests
import io
import base64
import asyncio
import requests
import aiohttp
import re
from PIL import Image
@ -107,21 +106,22 @@ class Dalle(Plugin):
"prompt": prompt
}
response = requests.post("https://nexra.aryahcr.cc/api/image/complements", headers=headers, data=json.dumps(data))
async with aiohttp.request("POST", "https://nexra.aryahcr.cc/api/image/complements", headers=headers, data=json.dumps(data)) as response:
if response.status_code != 200:
if response.status != 200:
self.log.warning(f"Unexpected status sending request to nexra.aryahcr.cc: {response.status_code}")
return
count = -1
for i in range(len(response.text)):
response_text = await response.text()
for i in range(len(response_text)):
if count <= -1:
if response.text[i] == "{":
if response_text[i] == "{":
count = i
else:
break
response_json = json.loads(response.text[count:])
response_json = json.loads(response_text[count:])
content = response_json['images'][0]
base64_str = content.replace("data:image/jpeg;base64,", "")
@ -132,4 +132,3 @@ class Dalle(Plugin):
mem_file.seek(0)
return mem_file

View File

@ -1,6 +1,6 @@
maubot: 0.1.0
id: sh.boehm.dalle
version: 0.0.029
version: 0.0.03
license: MIT
modules:
- dalle