mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
Merge pull request #368 from zyckk4/docstring-improvements
[Chore] 统一docstring格式
This commit is contained in:
commit
58d991df0a
|
@ -1,2 +1 @@
|
|||
"""OpenAI 接口处理及会话管理相关
|
||||
"""
|
||||
"""OpenAI 接口处理及会话管理相关"""
|
||||
|
|
|
@ -11,8 +11,7 @@ class KeysManager:
|
|||
"""所有api-key"""
|
||||
|
||||
using_key = ""
|
||||
"""当前使用的api-key
|
||||
"""
|
||||
"""当前使用的api-key"""
|
||||
|
||||
alerted = []
|
||||
"""已提示过超额的key
|
||||
|
@ -79,8 +78,7 @@ class KeysManager:
|
|||
self.api_key[key_name] = key
|
||||
|
||||
def set_current_exceeded(self):
|
||||
"""设置当前使用的api-key使用量超限
|
||||
"""
|
||||
"""设置当前使用的api-key使用量超限"""
|
||||
self.exceeded.append(self.using_key)
|
||||
|
||||
def get_key_name(self, api_key):
|
||||
|
|
|
@ -15,8 +15,7 @@ import pkg.plugin.settings as settings
|
|||
from mirai import Mirai
|
||||
|
||||
__plugins__ = {}
|
||||
"""
|
||||
插件列表
|
||||
"""插件列表
|
||||
|
||||
示例:
|
||||
{
|
||||
|
@ -35,14 +34,15 @@ __plugins__ = {}
|
|||
},
|
||||
"instance": None
|
||||
}
|
||||
}"""
|
||||
}
|
||||
"""
|
||||
|
||||
__plugins_order__ = []
|
||||
"""插件顺序"""
|
||||
|
||||
|
||||
def generate_plugin_order():
|
||||
""" 根据__plugin__生成插件初始顺序,无视是否启用 """
|
||||
"""根据__plugin__生成插件初始顺序,无视是否启用"""
|
||||
global __plugins_order__
|
||||
__plugins_order__ = []
|
||||
for plugin_name in __plugins__:
|
||||
|
@ -50,13 +50,13 @@ def generate_plugin_order():
|
|||
|
||||
|
||||
def iter_plugins():
|
||||
""" 按照顺序迭代插件 """
|
||||
"""按照顺序迭代插件"""
|
||||
for plugin_name in __plugins_order__:
|
||||
yield __plugins__[plugin_name]
|
||||
|
||||
|
||||
def iter_plugins_name():
|
||||
""" 迭代插件名 """
|
||||
"""迭代插件名"""
|
||||
for plugin_name in __plugins_order__:
|
||||
yield plugin_name
|
||||
|
||||
|
@ -85,7 +85,7 @@ def walk_plugin_path(module, prefix='', path_prefix=''):
|
|||
|
||||
|
||||
def load_plugins():
|
||||
""" 加载插件 """
|
||||
"""加载插件"""
|
||||
logging.info("加载插件")
|
||||
PluginHost()
|
||||
walk_plugin_path(__import__('plugins'))
|
||||
|
@ -102,7 +102,7 @@ def load_plugins():
|
|||
|
||||
|
||||
def initialize_plugins():
|
||||
""" 初始化插件 """
|
||||
"""初始化插件"""
|
||||
logging.info("初始化插件")
|
||||
import pkg.plugin.models as models
|
||||
for plugin in iter_plugins():
|
||||
|
@ -117,8 +117,7 @@ def initialize_plugins():
|
|||
|
||||
|
||||
def unload_plugins():
|
||||
""" 卸载插件
|
||||
"""
|
||||
"""卸载插件"""
|
||||
# 不再显式卸载插件,因为当程序结束时,插件的析构函数会被系统执行
|
||||
# for plugin in __plugins__.values():
|
||||
# if plugin['enabled'] and plugin['instance'] is not None:
|
||||
|
@ -134,7 +133,7 @@ def unload_plugins():
|
|||
|
||||
|
||||
def install_plugin(repo_url: str):
|
||||
""" 安装插件,从git储存库获取并解决依赖 """
|
||||
"""安装插件,从git储存库获取并解决依赖"""
|
||||
try:
|
||||
import pkg.utils.pkgmgr
|
||||
pkg.utils.pkgmgr.ensure_dulwich()
|
||||
|
@ -162,7 +161,7 @@ def install_plugin(repo_url: str):
|
|||
|
||||
|
||||
def uninstall_plugin(plugin_name: str) -> str:
|
||||
""" 卸载插件 """
|
||||
"""卸载插件"""
|
||||
if plugin_name not in __plugins__:
|
||||
raise Exception("插件不存在")
|
||||
|
||||
|
@ -178,17 +177,17 @@ def uninstall_plugin(plugin_name: str) -> str:
|
|||
|
||||
|
||||
class EventContext:
|
||||
""" 事件上下文 """
|
||||
"""事件上下文"""
|
||||
eid = 0
|
||||
"""事件编号"""
|
||||
|
||||
name = ""
|
||||
|
||||
__prevent_default__ = False
|
||||
""" 是否阻止默认行为 """
|
||||
"""是否阻止默认行为"""
|
||||
|
||||
__prevent_postorder__ = False
|
||||
""" 是否阻止后续插件的执行 """
|
||||
"""是否阻止后续插件的执行"""
|
||||
|
||||
__return_value__ = {}
|
||||
""" 返回值
|
||||
|
@ -251,7 +250,7 @@ class EventContext:
|
|||
|
||||
|
||||
def emit(event_name: str, **kwargs) -> EventContext:
|
||||
""" 触发事件 """
|
||||
"""触发事件"""
|
||||
import pkg.utils.context as context
|
||||
if context.get_plugin_host() is None:
|
||||
return None
|
||||
|
@ -290,7 +289,7 @@ class PluginHost:
|
|||
context.get_qqbot_manager().notify_admin(message)
|
||||
|
||||
def emit(self, event_name: str, **kwargs) -> EventContext:
|
||||
""" 触发事件 """
|
||||
"""触发事件"""
|
||||
import json
|
||||
|
||||
event_context = EventContext(event_name)
|
||||
|
|
|
@ -7,7 +7,7 @@ import pkg.plugin.host as host
|
|||
|
||||
|
||||
def wrapper_dict_from_plugin_list() -> dict:
|
||||
""" 将插件列表转换为开关json """
|
||||
"""将插件列表转换为开关json"""
|
||||
switch = {}
|
||||
|
||||
for plugin_name in host.__plugins__:
|
||||
|
@ -30,7 +30,7 @@ def apply_switch(switch: dict):
|
|||
|
||||
|
||||
def dump_switch():
|
||||
""" 保存开关数据 """
|
||||
"""保存开关数据"""
|
||||
logging.debug("保存开关数据")
|
||||
# 将开关数据写入plugins/switch.json
|
||||
|
||||
|
@ -41,7 +41,7 @@ def dump_switch():
|
|||
|
||||
|
||||
def load_switch():
|
||||
""" 加载开关数据 """
|
||||
"""加载开关数据"""
|
||||
logging.debug("加载开关数据")
|
||||
# 读取plugins/switch.json
|
||||
|
||||
|
|
|
@ -4,9 +4,7 @@ from concurrent.futures import ThreadPoolExecutor
|
|||
|
||||
|
||||
class Pool:
|
||||
'''
|
||||
线程池结构
|
||||
'''
|
||||
"""线程池结构"""
|
||||
pool_num:int = None
|
||||
ctl:ThreadPoolExecutor = None
|
||||
task_list:list = None
|
||||
|
@ -33,12 +31,11 @@ class Pool:
|
|||
|
||||
class ThreadCtl:
|
||||
def __init__(self, sys_pool_num, admin_pool_num, user_pool_num):
|
||||
'''
|
||||
线程池控制类
|
||||
"""线程池控制类
|
||||
sys_pool_num:分配系统使用的线程池数量(>=8)
|
||||
admin_pool_num:用于处理管理员消息的线程池数量(>=1)
|
||||
user_pool_num:分配用于处理用户消息的线程池的数量(>=1)
|
||||
'''
|
||||
"""
|
||||
if sys_pool_num < 5:
|
||||
raise Exception("Too few system threads(sys_pool_num needs >= 8, but received {})".format(sys_pool_num))
|
||||
if admin_pool_num < 1:
|
||||
|
|
Loading…
Reference in New Issue
Block a user