add ImageGen

This commit is contained in:
RA
2023-03-25 02:22:21 +08:00
parent 2b003eae0c
commit 54a866b3e1
5 changed files with 9 additions and 4 deletions

4
app.py
View File

@@ -8,8 +8,9 @@ from multiprocessing import Pool
# 启动通道
def start_process(channel_type):
# 若为多进程启动,子进程无法直接访问主进程的内存空间,重新创建config类
config.load_config()
model_type = config.conf().get("model").get("type")
# load config
log.info("[INIT] Start up: {} on {}", model_type, channel_type)
# create channel
@@ -18,7 +19,6 @@ def start_process(channel_type):
# startup channel
channel.startup()
if __name__ == '__main__':
try:
# load config

View File

@@ -73,6 +73,8 @@ class HttpChannel(Channel):
context['from_user_id'] = str(id)
reply = super().build_reply_content(data["msg"], context)
if img_match_prefix:
if not isinstance(reply, list):
return reply
images = ""
for url in reply:
images += f"[!['IMAGE_CREATE']({url})]({url})\n"

View File

@@ -52,6 +52,8 @@ class TelegramChannel(Channel):
img_urls = super().build_reply_content(msg.text, context)
if not img_urls:
return
if not isinstance(img_urls, list):
return img_urls
for url in img_urls:
# 图片下载
pic_res = requests.get(url, stream=True)

View File

@@ -171,7 +171,8 @@ class WechatChannel(Channel):
img_urls = super().build_reply_content(query, context)
if not img_urls:
return
if not isinstance(img_urls, list):
return img_urls
for url in img_urls:
# 图片下载
pic_res = requests.get(url, stream=True)

View File

@@ -97,7 +97,7 @@ class BingModel(Model):
image_generator = ImageGen(cookie_value)
img_list = image_generator.get_images(query)
log.info("[NewBing] image_list={}".format(img_list))
return img_list[0]
return img_list
except Exception as e:
log.exception(e)
return None