diff --git a/bot/openai/open_ai_image.py b/bot/openai/open_ai_image.py index 830abfc..5dbbd23 100644 --- a/bot/openai/open_ai_image.py +++ b/bot/openai/open_ai_image.py @@ -23,7 +23,9 @@ class OpenAIImage(object): response = openai.Image.create( prompt=query, # 图片描述 n=1, # 每次生成图片的数量 - size="256x256", # 图片大小,可选有 256x256, 512x512, 1024x1024 + size=conf().get( + "image_create_size", "256x256" + ), # 图片大小,可选有 256x256, 512x512, 1024x1024 ) image_url = response["data"][0]["url"] logger.info("[OPEN_AI] image_url={}".format(image_url)) diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index ce5ad96..52c8ee3 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -20,7 +20,7 @@ from common.expired_dict import ExpiredDict from common.log import logger from common.singleton import singleton from common.time_check import time_checker -from config import conf +from config import conf, get_appdata_dir from lib import itchat from lib.itchat.content import * from plugins import * @@ -116,13 +116,19 @@ class WechatChannel(ChatChannel): itchat.instance.receivingRetryCount = 600 # 修改断线超时时间 # login by scan QRCode hotReload = conf().get("hot_reload", False) + status_path = os.path.join(get_appdata_dir(), "itchat.pkl") try: - itchat.auto_login(enableCmdQR=2, hotReload=hotReload, qrCallback=qrCallback) + itchat.auto_login( + enableCmdQR=2, + hotReload=hotReload, + statusStorageDir=status_path, + qrCallback=qrCallback, + ) except Exception as e: if hotReload: logger.error("Hot reload failed, try to login without hot reload") itchat.logout() - os.remove("itchat.pkl") + os.remove(status_path) itchat.auto_login( enableCmdQR=2, hotReload=hotReload, qrCallback=qrCallback ) diff --git a/config.py b/config.py index 6e6260e..8f5d2ca 100644 --- a/config.py +++ b/config.py @@ -31,6 +31,7 @@ available_setting = { "trigger_by_self": False, # 是否允许机器人触发 "image_create_prefix": ["画", "看", "找"], # 开启图片回复的前缀 "concurrency_in_session": 1, # 同一会话最多有多少条消息在处理中,大于1可能乱序 + "image_create_size": "256x256", # 图片大小,可选有 256x256, 512x512, 1024x1024 # chatgpt会话参数 "expires_in_seconds": 3600, # 无操作会话的过期时间 "character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。", # 人格描述 @@ -79,6 +80,7 @@ available_setting = { # channel配置 "channel_type": "wx", # 通道类型,支持:{wx,wxy,terminal,wechatmp,wechatmp_service} "debug": False, # 是否开启debug模式,开启后会打印更多日志 + "appdata_dir": "", # 数据目录 # 插件配置 "plugin_trigger_prefix": "$", # 规范插件提供聊天相关指令的前缀,建议不要和管理员指令前缀"#"冲突 } @@ -116,7 +118,7 @@ class Config(dict): def load_user_datas(self): try: - with open("user_datas.pkl", "rb") as f: + with open(os.path.join(get_appdata_dir(), "user_datas.pkl"), "rb") as f: self.user_datas = pickle.load(f) logger.info("[Config] User datas loaded.") except FileNotFoundError as e: @@ -127,7 +129,7 @@ class Config(dict): def save_user_datas(self): try: - with open("user_datas.pkl", "wb") as f: + with open(os.path.join(get_appdata_dir(), "user_datas.pkl"), "wb") as f: pickle.dump(self.user_datas, f) logger.info("[Config] User datas saved.") except Exception as e: @@ -188,3 +190,11 @@ def read_file(path): def conf(): return config + + +def get_appdata_dir(): + data_path = os.path.join(get_root(), conf().get("appdata_dir", "")) + if not os.path.exists(data_path): + logger.info("[INIT] data path not exists, create it: {}".format(data_path)) + os.makedirs(data_path) + return data_path diff --git a/docker/build.latest.sh b/docker/build.latest.sh index 0f06f82..92c3564 100644 --- a/docker/build.latest.sh +++ b/docker/build.latest.sh @@ -1,4 +1,8 @@ #!/bin/bash +unset KUBECONFIG + cd .. && docker build -f docker/Dockerfile.latest \ - -t zhayujie/chatgpt-on-wechat . \ No newline at end of file + -t zhayujie/chatgpt-on-wechat . + +docker tag zhayujie/chatgpt-on-wechat zhayujie/chatgpt-on-wechat:$(date +%y%m%d) \ No newline at end of file