mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
feat: 命令行退出方式
This commit is contained in:
parent
836df87e18
commit
abc19e78b8
|
@ -4,6 +4,8 @@ import logging
|
||||||
import asyncio
|
import asyncio
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import aioconsole
|
||||||
|
|
||||||
from ..platform import manager as im_mgr
|
from ..platform import manager as im_mgr
|
||||||
from ..provider.session import sessionmgr as llm_session_mgr
|
from ..provider.session import sessionmgr as llm_session_mgr
|
||||||
from ..provider.requester import modelmgr as llm_model_mgr
|
from ..provider.requester import modelmgr as llm_model_mgr
|
||||||
|
@ -72,11 +74,21 @@ class Application:
|
||||||
tasks = []
|
tasks = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|
||||||
tasks = [
|
tasks = [
|
||||||
asyncio.create_task(self.im_mgr.run()),
|
asyncio.create_task(self.im_mgr.run()),
|
||||||
asyncio.create_task(self.ctrl.run())
|
asyncio.create_task(self.ctrl.run())
|
||||||
]
|
]
|
||||||
await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
|
|
||||||
|
async def interrupt(tasks):
|
||||||
|
await asyncio.sleep(1.5)
|
||||||
|
while await aioconsole.ainput("使用 exit 退出程序 > ") != 'exit':
|
||||||
|
pass
|
||||||
|
for task in tasks:
|
||||||
|
task.cancel()
|
||||||
|
|
||||||
|
await interrupt(tasks)
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -13,7 +13,8 @@ class RandomRespRule(rule_model.GroupRespondRule):
|
||||||
self,
|
self,
|
||||||
message_text: str,
|
message_text: str,
|
||||||
message_chain: mirai.MessageChain,
|
message_chain: mirai.MessageChain,
|
||||||
rule_dict: dict
|
rule_dict: dict,
|
||||||
|
query: core_entities.Query
|
||||||
) -> entities.RuleJudgeResult:
|
) -> entities.RuleJudgeResult:
|
||||||
random_rate = rule_dict['random']
|
random_rate = rule_dict['random']
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ class RegExpRule(rule_model.GroupRespondRule):
|
||||||
self,
|
self,
|
||||||
message_text: str,
|
message_text: str,
|
||||||
message_chain: mirai.MessageChain,
|
message_chain: mirai.MessageChain,
|
||||||
rule_dict: dict
|
rule_dict: dict,
|
||||||
|
query: core_entities.Query
|
||||||
) -> entities.RuleJudgeResult:
|
) -> entities.RuleJudgeResult:
|
||||||
regexps = rule_dict['regexp']
|
regexps = rule_dict['regexp']
|
||||||
|
|
||||||
|
|
|
@ -78,13 +78,6 @@ class PlatformManager:
|
||||||
adapter=adapter
|
adapter=adapter
|
||||||
)
|
)
|
||||||
|
|
||||||
# nakuru不区分好友和陌生人,故仅为yirimirai注册陌生人事件
|
|
||||||
# if self.ap.platform_cfg.data['platform-adapter'] == 'yiri-mirai':
|
|
||||||
# self.adapter.register_listener(
|
|
||||||
# StrangerMessage,
|
|
||||||
# on_stranger_message
|
|
||||||
# )
|
|
||||||
|
|
||||||
async def on_group_message(event: GroupMessage, adapter: msadapter.MessageSourceAdapter):
|
async def on_group_message(event: GroupMessage, adapter: msadapter.MessageSourceAdapter):
|
||||||
|
|
||||||
event_ctx = await self.ap.plugin_mgr.emit_event(
|
event_ctx = await self.ap.plugin_mgr.emit_event(
|
||||||
|
@ -187,7 +180,10 @@ class PlatformManager:
|
||||||
tasks = []
|
tasks = []
|
||||||
for adapter in self.adapters:
|
for adapter in self.adapters:
|
||||||
tasks.append(adapter.run_async())
|
tasks.append(adapter.run_async())
|
||||||
await asyncio.gather(*tasks)
|
|
||||||
|
for task in tasks:
|
||||||
|
asyncio.create_task(task)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.ap.logger.error('平台适配器运行出错: ' + str(e))
|
self.ap.logger.error('平台适配器运行出错: ' + str(e))
|
||||||
self.ap.logger.debug(f"Traceback: {traceback.format_exc()}")
|
self.ap.logger.debug(f"Traceback: {traceback.format_exc()}")
|
||||||
|
|
|
@ -14,3 +14,4 @@ tiktoken
|
||||||
PyYaml
|
PyYaml
|
||||||
aiohttp
|
aiohttp
|
||||||
pydantic
|
pydantic
|
||||||
|
aioconsole
|
Loading…
Reference in New Issue
Block a user