diff --git a/channel/http/http_channel.py b/channel/http/http_channel.py index e813b5a..3dc726f 100644 --- a/channel/http/http_channel.py +++ b/channel/http/http_channel.py @@ -9,6 +9,7 @@ from common import functions from config import channel_conf from config import channel_conf_val from channel.channel import Channel + http_app = Flask(__name__,) # 自动重载模板文件 http_app.jinja_env.auto_reload = True @@ -63,11 +64,10 @@ class HttpChannel(Channel): def handle(self, data): context = dict() - img_match_prefix = functions.check_prefix(data["msg"], channel_conf_val(const.HTTP, 'image_create_prefix')) + img_match_prefix = functions.check_prefix( + data["msg"], channel_conf_val(const.HTTP, 'image_create_prefix')) if img_match_prefix: data["msg"] = data["msg"].split(img_match_prefix, 1)[1].strip() - if functions.contain_chinese(data["msg"]): - return "ImageGen目前仅支持使用英文关键词生成图片" context['type'] = 'IMAGE_CREATE' id = data["id"] context['from_user_id'] = str(id) @@ -75,6 +75,6 @@ class HttpChannel(Channel): if img_match_prefix: images = "" for url in reply: - images+=f"[!['IMAGE_CREATE']({url})]({url})\n" - reply=images + images += f"[!['IMAGE_CREATE']({url})]({url})\n" + reply = images return reply diff --git a/model/bing/new_bing_model.py b/model/bing/new_bing_model.py index ce4bd63..b22244b 100644 --- a/model/bing/new_bing_model.py +++ b/model/bing/new_bing_model.py @@ -5,6 +5,8 @@ from config import model_conf_val from common import log from EdgeGPT import Chatbot, ConversationStyle from ImageGen import ImageGen +from common import functions + user_session = dict() suggestion_session = dict() # newBing对话模型逆向网页gitAPI @@ -84,12 +86,14 @@ class BingModel(Model): log.warn("[NewBing] reply={}", answer) return "对话被接口拒绝,已开启新的一轮对话。" elif context.get('type', None) == 'IMAGE_CREATE': + if functions.contain_chinese(query): + return "ImageGen目前仅支持使用英文关键词生成图片" return self.create_img(query) def create_img(self, query): try: log.info("[NewBing] image_query={}".format(query)) - cookie_value=self.cookies[0]["value"] + cookie_value = self.cookies[0]["value"] image_generator = ImageGen(cookie_value) img_list = image_generator.get_images(query) log.info("[NewBing] image_list={}".format(img_list))