mirror of
https://github.com/zhayujie/bot-on-anything.git
synced 2026-02-14 08:16:20 +08:00
add ImageGen
This commit is contained in:
4
app.py
4
app.py
@@ -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
|
||||
|
||||
@@ -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"[]({url})\n"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user