2024-01-23 20:55:20 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import logging
|
2024-01-26 15:51:49 +08:00
|
|
|
import asyncio
|
2024-01-23 20:55:20 +08:00
|
|
|
|
|
|
|
from ..qqbot import manager as qqbot_mgr
|
|
|
|
from ..openai import manager as openai_mgr
|
2024-01-27 00:06:38 +08:00
|
|
|
from ..openai.session import sessionmgr as llm_session_mgr
|
|
|
|
from ..openai.requester import modelmgr as llm_model_mgr
|
|
|
|
from ..openai.sysprompt import sysprompt as llm_prompt_mgr
|
2024-01-27 21:50:40 +08:00
|
|
|
from ..openai.tools import toolmgr as llm_tool_mgr
|
2024-01-23 20:55:20 +08:00
|
|
|
from ..config import manager as config_mgr
|
|
|
|
from ..database import manager as database_mgr
|
|
|
|
from ..utils.center import v2 as center_mgr
|
2024-01-23 22:28:30 +08:00
|
|
|
from ..plugin import host as plugin_host
|
2024-01-26 15:51:49 +08:00
|
|
|
from . import pool, controller
|
|
|
|
from ..pipeline import stagemgr
|
2024-01-23 20:55:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Application:
|
|
|
|
im_mgr: qqbot_mgr.QQBotManager = None
|
|
|
|
|
|
|
|
llm_mgr: openai_mgr.OpenAIInteract = None
|
|
|
|
|
2024-01-27 00:06:38 +08:00
|
|
|
sess_mgr: llm_session_mgr.SessionManager = None
|
|
|
|
|
|
|
|
model_mgr: llm_model_mgr.ModelManager = None
|
|
|
|
|
|
|
|
prompt_mgr: llm_prompt_mgr.PromptManager = None
|
|
|
|
|
2024-01-27 21:50:40 +08:00
|
|
|
tool_mgr: llm_tool_mgr.ToolManager = None
|
|
|
|
|
2024-01-23 20:55:20 +08:00
|
|
|
cfg_mgr: config_mgr.ConfigManager = None
|
|
|
|
|
|
|
|
tips_mgr: config_mgr.ConfigManager = None
|
|
|
|
|
|
|
|
db_mgr: database_mgr.DatabaseManager = None
|
|
|
|
|
|
|
|
ctr_mgr: center_mgr.V2CenterAPI = None
|
|
|
|
|
2024-01-26 15:51:49 +08:00
|
|
|
query_pool: pool.QueryPool = None
|
|
|
|
|
|
|
|
ctrl: controller.Controller = None
|
|
|
|
|
|
|
|
stage_mgr: stagemgr.StageManager = None
|
|
|
|
|
2024-01-23 20:55:20 +08:00
|
|
|
logger: logging.Logger = None
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
2024-01-27 21:50:40 +08:00
|
|
|
async def initialize(self):
|
2024-01-23 22:28:30 +08:00
|
|
|
plugin_host.initialize_plugins()
|
|
|
|
|
2024-01-27 21:50:40 +08:00
|
|
|
# 把现有的所有内容函数加到toolmgr里
|
|
|
|
for func in plugin_host.__callable_functions__:
|
|
|
|
print(func)
|
|
|
|
self.tool_mgr.register_legacy_function(
|
|
|
|
name=func['name'],
|
|
|
|
description=func['description'],
|
|
|
|
parameters=func['parameters'],
|
|
|
|
func=plugin_host.__function_inst_map__[func['name']]
|
|
|
|
)
|
|
|
|
|
|
|
|
async def run(self):
|
|
|
|
|
2024-01-26 15:51:49 +08:00
|
|
|
tasks = [
|
|
|
|
asyncio.create_task(self.im_mgr.run()),
|
|
|
|
asyncio.create_task(self.ctrl.run())
|
|
|
|
]
|
|
|
|
|
|
|
|
await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
|