switch from request to aiohttp
This commit is contained in:
parent
3c0b9664ff
commit
5473df0e5d
2 changed files with 24 additions and 25 deletions
15
dalle.py
15
dalle.py
|
@ -1,10 +1,9 @@
|
||||||
import json
|
import json
|
||||||
import urllib
|
import urllib
|
||||||
import requests
|
|
||||||
import io
|
import io
|
||||||
import base64
|
import base64
|
||||||
import asyncio
|
import asyncio
|
||||||
import requests
|
import aiohttp
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
@ -107,21 +106,22 @@ class Dalle(Plugin):
|
||||||
"prompt": prompt
|
"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}")
|
self.log.warning(f"Unexpected status sending request to nexra.aryahcr.cc: {response.status_code}")
|
||||||
return
|
return
|
||||||
|
|
||||||
count = -1
|
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 count <= -1:
|
||||||
if response.text[i] == "{":
|
if response_text[i] == "{":
|
||||||
count = i
|
count = i
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
response_json = json.loads(response.text[count:])
|
|
||||||
|
|
||||||
|
response_json = json.loads(response_text[count:])
|
||||||
content = response_json['images'][0]
|
content = response_json['images'][0]
|
||||||
|
|
||||||
base64_str = content.replace("data:image/jpeg;base64,", "")
|
base64_str = content.replace("data:image/jpeg;base64,", "")
|
||||||
|
@ -132,4 +132,3 @@ class Dalle(Plugin):
|
||||||
mem_file.seek(0)
|
mem_file.seek(0)
|
||||||
|
|
||||||
return mem_file
|
return mem_file
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
maubot: 0.1.0
|
maubot: 0.1.0
|
||||||
id: sh.boehm.dalle
|
id: sh.boehm.dalle
|
||||||
version: 0.0.029
|
version: 0.0.03
|
||||||
license: MIT
|
license: MIT
|
||||||
modules:
|
modules:
|
||||||
- dalle
|
- dalle
|
||||||
|
|
Loading…
Reference in a new issue