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