mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-21 06:07:13 +08:00
feat: add global admin config
This commit is contained in:
@@ -102,6 +102,8 @@ available_setting = {
|
|||||||
"appdata_dir": "", # 数据目录
|
"appdata_dir": "", # 数据目录
|
||||||
# 插件配置
|
# 插件配置
|
||||||
"plugin_trigger_prefix": "$", # 规范插件提供聊天相关指令的前缀,建议不要和管理员指令前缀"#"冲突
|
"plugin_trigger_prefix": "$", # 规范插件提供聊天相关指令的前缀,建议不要和管理员指令前缀"#"冲突
|
||||||
|
# 是否使用全局插件配置
|
||||||
|
"use_global_plugin_config": False,
|
||||||
# 知识库平台配置
|
# 知识库平台配置
|
||||||
"use_linkai": False,
|
"use_linkai": False,
|
||||||
"linkai_api_key": "",
|
"linkai_api_key": "",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ services:
|
|||||||
SPEECH_RECOGNITION: 'False'
|
SPEECH_RECOGNITION: 'False'
|
||||||
CHARACTER_DESC: '你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。'
|
CHARACTER_DESC: '你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。'
|
||||||
EXPIRES_IN_SECONDS: 3600
|
EXPIRES_IN_SECONDS: 3600
|
||||||
|
USE_GLOBAL_PLUGIN_CONFIG: 'True'
|
||||||
USE_LINKAI: 'False'
|
USE_LINKAI: 'False'
|
||||||
LINKAI_API_KEY: ''
|
LINKAI_API_KEY: ''
|
||||||
LINKAI_APP_CODE: ''
|
LINKAI_APP_CODE: ''
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class LinkAI(Plugin):
|
|||||||
:param e_context: 消息上下文
|
:param e_context: 消息上下文
|
||||||
"""
|
"""
|
||||||
context = e_context['context']
|
context = e_context['context']
|
||||||
if context.type not in [ContextType.TEXT, ContextType.IMAGE]:
|
if context.type not in [ContextType.TEXT, ContextType.IMAGE, ContextType.IMAGE_CREATE]:
|
||||||
# filter content no need solve
|
# filter content no need solve
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -114,11 +114,11 @@ class LinkAI(Plugin):
|
|||||||
|
|
||||||
def get_help_text(self, verbose=False, **kwargs):
|
def get_help_text(self, verbose=False, **kwargs):
|
||||||
trigger_prefix = _get_trigger_prefix()
|
trigger_prefix = _get_trigger_prefix()
|
||||||
help_text = "用于集成 LinkAI 提供的文本对话、知识库、绘画等能力。\n"
|
help_text = "用于集成 LinkAI 提供的知识库、Midjourney绘画等能力。\n\n"
|
||||||
if not verbose:
|
if not verbose:
|
||||||
return help_text
|
return help_text
|
||||||
help_text += ""
|
help_text += f'📖 知识库\n - 群聊中指定应用: {trigger_prefix}linkai app 应用编码\n\n例如: \n"$linkai app Kv2fXJcH"\n\n'
|
||||||
help_text += f"{trigger_prefix}mj 描述词1,描述词2 ... : 利用描述词作画,参数请放在提示词之后。\n\n{trigger_prefix}mju ID 图片序号: 对指定ID消息中的第x张图片进行放大。\n例如:\n\"{trigger_prefix}mj a little cat, white --ar 9:16\"\n\"{trigger_prefix}mjimage a white cat --ar 9:16\"\n\"{trigger_prefix}mju 1105592717188272288 2\""
|
help_text += f"🎨 绘画\n - 生成: {trigger_prefix}mj 描述词1, 描述词2.. \n - 放大: {trigger_prefix}mju 图片ID 图片序号\n\n例如:\n\"{trigger_prefix}mj a little cat, white --ar 9:16\"\n\"{trigger_prefix}mju 1105592717188272288 2\""
|
||||||
return help_text
|
return help_text
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -75,9 +75,8 @@ class MJBot:
|
|||||||
return TaskType.GENERATE
|
return TaskType.GENERATE
|
||||||
elif cmd_list[0].lower() == f"{trigger_prefix}mju":
|
elif cmd_list[0].lower() == f"{trigger_prefix}mju":
|
||||||
return TaskType.UPSCALE
|
return TaskType.UPSCALE
|
||||||
elif self.config.get("use_image_create_prefix") and \
|
elif context.type == ContextType.IMAGE_CREATE and self.config.get("use_image_create_prefix"):
|
||||||
check_prefix(context.content, conf().get("image_create_prefix")):
|
return TaskType.GENERATE
|
||||||
return TaskType.GENERATE
|
|
||||||
|
|
||||||
|
|
||||||
def process_mj_task(self, mj_type: TaskType, e_context: EventContext):
|
def process_mj_task(self, mj_type: TaskType, e_context: EventContext):
|
||||||
@@ -89,7 +88,7 @@ class MJBot:
|
|||||||
context = e_context['context']
|
context = e_context['context']
|
||||||
session_id = context["session_id"]
|
session_id = context["session_id"]
|
||||||
cmd = context.content.split(maxsplit=1)
|
cmd = context.content.split(maxsplit=1)
|
||||||
if len(cmd) == 1:
|
if len(cmd) == 1 and context.type == ContextType.TEXT:
|
||||||
self._set_reply_text(self.get_help_text(verbose=True), e_context, level=ReplyType.INFO)
|
self._set_reply_text(self.get_help_text(verbose=True), e_context, level=ReplyType.INFO)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -98,9 +97,8 @@ class MJBot:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if mj_type == TaskType.GENERATE:
|
if mj_type == TaskType.GENERATE:
|
||||||
image_prefix = check_prefix(context.content, conf().get("image_create_prefix"))
|
if context.type == ContextType.IMAGE_CREATE:
|
||||||
if image_prefix:
|
raw_prompt = context.content
|
||||||
raw_prompt = context.content.replace(image_prefix, "", 1)
|
|
||||||
else:
|
else:
|
||||||
# 图片生成
|
# 图片生成
|
||||||
raw_prompt = cmd[1]
|
raw_prompt = cmd[1]
|
||||||
@@ -155,7 +153,7 @@ class MJBot:
|
|||||||
time_str = "1~10分钟"
|
time_str = "1~10分钟"
|
||||||
else:
|
else:
|
||||||
time_str = "1~2分钟"
|
time_str = "1~2分钟"
|
||||||
content = f"🚀你的作品将在{time_str}左右完成,请耐心等待\n- - - - - - - - -\n"
|
content = f"🚀您的作品将在{time_str}左右完成,请耐心等待\n- - - - - - - - -\n"
|
||||||
if real_prompt:
|
if real_prompt:
|
||||||
content += f"初始prompt: {prompt}\n转换后prompt: {real_prompt}"
|
content += f"初始prompt: {prompt}\n转换后prompt: {real_prompt}"
|
||||||
else:
|
else:
|
||||||
@@ -205,20 +203,25 @@ class MJBot:
|
|||||||
await asyncio.sleep(10)
|
await asyncio.sleep(10)
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
url = f"{self.base_url}/tasks/{task.id}"
|
url = f"{self.base_url}/tasks/{task.id}"
|
||||||
async with session.get(url, headers=self.headers) as res:
|
try:
|
||||||
if res.status == 200:
|
async with session.get(url, headers=self.headers) as res:
|
||||||
res_json = await res.json()
|
if res.status == 200:
|
||||||
logger.debug(f"[MJ] task check res, task_id={task.id}, status={res.status}, "
|
res_json = await res.json()
|
||||||
f"data={res_json.get('data')}, thread={threading.current_thread().name}")
|
logger.debug(f"[MJ] task check res, task_id={task.id}, status={res.status}, "
|
||||||
if res_json.get("data") and res_json.get("data").get("status") == Status.FINISHED.name:
|
f"data={res_json.get('data')}, thread={threading.current_thread().name}")
|
||||||
# process success res
|
if res_json.get("data") and res_json.get("data").get("status") == Status.FINISHED.name:
|
||||||
if self.tasks.get(task.id):
|
# process success res
|
||||||
self.tasks[task.id].status = Status.FINISHED
|
if self.tasks.get(task.id):
|
||||||
self._process_success_task(task, res_json.get("data"), e_context)
|
self.tasks[task.id].status = Status.FINISHED
|
||||||
return
|
self._process_success_task(task, res_json.get("data"), e_context)
|
||||||
else:
|
return
|
||||||
logger.warn(f"[MJ] image check error, status_code={res.status}")
|
else:
|
||||||
max_retry_times -= 20
|
res_json = await res.json()
|
||||||
|
logger.warn(f"[MJ] image check error, status_code={res.status}, res={res_json}")
|
||||||
|
max_retry_times -= 20
|
||||||
|
except Exception as e:
|
||||||
|
max_retry_times -= 20
|
||||||
|
logger.warn(e)
|
||||||
max_retry_times -= 1
|
max_retry_times -= 1
|
||||||
logger.warn("[MJ] end from poll")
|
logger.warn("[MJ] end from poll")
|
||||||
if self.tasks.get(task.id):
|
if self.tasks.get(task.id):
|
||||||
@@ -308,10 +311,11 @@ class MJBot:
|
|||||||
|
|
||||||
def get_help_text(self, verbose=False, **kwargs):
|
def get_help_text(self, verbose=False, **kwargs):
|
||||||
trigger_prefix = conf().get("plugin_trigger_prefix", "$")
|
trigger_prefix = conf().get("plugin_trigger_prefix", "$")
|
||||||
help_text = "利用midjourney来画图。\n"
|
help_text = "🎨利用Midjourney进行画图\n\n"
|
||||||
if not verbose:
|
if not verbose:
|
||||||
return help_text
|
return help_text
|
||||||
help_text += f"{trigger_prefix}mj 描述词1,描述词2 ... : 利用描述词作画,参数请放在提示词之后。\n{trigger_prefix}mjimage 描述词1,描述词2 ... : 利用描述词进行图生图,参数请放在提示词之后。\n{trigger_prefix}mjr ID: 对指定ID消息重新生成图片。\n{trigger_prefix}mju ID 图片序号: 对指定ID消息中的第x张图片进行放大。\n{trigger_prefix}mjv ID 图片序号: 对指定ID消息中的第x张图片进行变换。\n例如:\n\"{trigger_prefix}mj a little cat, white --ar 9:16\"\n\"{trigger_prefix}mjimage a white cat --ar 9:16\"\n\"{trigger_prefix}mju 1105592717188272288 2\""
|
help_text += f" - 生成: {trigger_prefix}mj 描述词1, 描述词2.. \n - 放大: {trigger_prefix}mju 图片ID 图片序号\n\n例如:\n\"{trigger_prefix}mj a little cat, white --ar 9:16\"\n\"{trigger_prefix}mju 1105592717188272288 2\""
|
||||||
|
|
||||||
return help_text
|
return help_text
|
||||||
|
|
||||||
def find_tasks_by_user_id(self, user_id) -> list[MJTask]:
|
def find_tasks_by_user_id(self, user_id) -> list[MJTask]:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from config import pconf, plugin_config
|
from config import pconf, plugin_config, conf
|
||||||
from common.log import logger
|
from common.log import logger
|
||||||
|
|
||||||
|
|
||||||
@@ -15,8 +15,8 @@ class Plugin:
|
|||||||
"""
|
"""
|
||||||
# 优先获取 plugins/config.json 中的全局配置
|
# 优先获取 plugins/config.json 中的全局配置
|
||||||
plugin_conf = pconf(self.name)
|
plugin_conf = pconf(self.name)
|
||||||
if not plugin_conf:
|
if not plugin_conf or not conf().get("use_global_plugin_config"):
|
||||||
# 全局配置不存在,则获取插件目录下的配置
|
# 全局配置不存在 或者 未开启全局配置开关,则获取插件目录下的配置
|
||||||
plugin_config_path = os.path.join(self.path, "config.json")
|
plugin_config_path = os.path.join(self.path, "config.json")
|
||||||
if os.path.exists(plugin_config_path):
|
if os.path.exists(plugin_config_path):
|
||||||
with open(plugin_config_path, "r") as f:
|
with open(plugin_config_path, "r") as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user