Skip to content

Commit

Permalink
feat: supports for provider reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Jan 4, 2025
1 parent 5e5a363 commit 97bb24c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/api/http/controller/groups/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class LogsRouterGroup(group.RouterGroup):

async def initialize(self) -> None:
@self.route('', methods=['GET'])
@self.route('', methods=['GET'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:

start_page_number = int(quart.request.args.get('start_page_number', 0))
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/http/controller/groups/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class PluginsRouterGroup(group.RouterGroup):

async def initialize(self) -> None:
@self.route('', methods=['GET'])
@self.route('', methods=['GET'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:
plugins = self.ap.plugin_mgr.plugins()

Expand All @@ -23,14 +23,14 @@ async def _() -> str:
'plugins': plugins_data
})

@self.route('/<author>/<plugin_name>/toggle', methods=['PUT'])
@self.route('/<author>/<plugin_name>/toggle', methods=['PUT'], auth_type=group.AuthType.USER_TOKEN)
async def _(author: str, plugin_name: str) -> str:
data = await quart.request.json
target_enabled = data.get('target_enabled')
await self.ap.plugin_mgr.update_plugin_switch(plugin_name, target_enabled)
return self.success()

@self.route('/<author>/<plugin_name>/update', methods=['POST'])
@self.route('/<author>/<plugin_name>/update', methods=['POST'], auth_type=group.AuthType.USER_TOKEN)
async def _(author: str, plugin_name: str) -> str:
ctx = taskmgr.TaskContext.new()
wrapper = self.ap.task_mgr.create_user_task(
Expand All @@ -44,7 +44,7 @@ async def _(author: str, plugin_name: str) -> str:
'task_id': wrapper.id
})

@self.route('/<author>/<plugin_name>', methods=['DELETE'])
@self.route('/<author>/<plugin_name>', methods=['DELETE'], auth_type=group.AuthType.USER_TOKEN)
async def _(author: str, plugin_name: str) -> str:
ctx = taskmgr.TaskContext.new()
wrapper = self.ap.task_mgr.create_user_task(
Expand All @@ -59,13 +59,13 @@ async def _(author: str, plugin_name: str) -> str:
'task_id': wrapper.id
})

@self.route('/reorder', methods=['PUT'])
@self.route('/reorder', methods=['PUT'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:
data = await quart.request.json
await self.ap.plugin_mgr.reorder_plugins(data.get('plugins'))
return self.success()

@self.route('/install/github', methods=['POST'])
@self.route('/install/github', methods=['POST'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:
data = await quart.request.json

Expand Down
6 changes: 3 additions & 3 deletions pkg/api/http/controller/groups/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SettingsRouterGroup(group.RouterGroup):

async def initialize(self) -> None:

@self.route('', methods=['GET'])
@self.route('', methods=['GET'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:
return self.success(
data={
Expand All @@ -23,7 +23,7 @@ async def _() -> str:
}
)

@self.route('/<manager_name>', methods=['GET'])
@self.route('/<manager_name>', methods=['GET'], auth_type=group.AuthType.USER_TOKEN)
async def _(manager_name: str) -> str:

manager = self.ap.settings_mgr.get_manager(manager_name)
Expand All @@ -44,7 +44,7 @@ async def _(manager_name: str) -> str:
}
)

@self.route('/<manager_name>/data', methods=['PUT'])
@self.route('/<manager_name>/data', methods=['PUT'], auth_type=group.AuthType.USER_TOKEN)
async def _(manager_name: str) -> str:
data = await quart.request.json
manager = self.ap.settings_mgr.get_manager(manager_name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/http/controller/groups/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class StatsRouterGroup(group.RouterGroup):

async def initialize(self) -> None:
@self.route('/basic', methods=['GET'])
@self.route('/basic', methods=['GET'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:

conv_count = 0
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/http/controller/groups/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def _() -> str:
}
)

@self.route('/tasks', methods=['GET'])
@self.route('/tasks', methods=['GET'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:
task_type = quart.request.args.get("type")

Expand All @@ -31,7 +31,7 @@ async def _() -> str:
data=self.ap.task_mgr.get_tasks_dict(task_type)
)

@self.route('/tasks/<task_id>', methods=['GET'])
@self.route('/tasks/<task_id>', methods=['GET'], auth_type=group.AuthType.USER_TOKEN)
async def _(task_id: str) -> str:
task = self.ap.task_mgr.get_task_by_id(int(task_id))

Expand All @@ -40,7 +40,7 @@ async def _(task_id: str) -> str:

return self.success(data=task.to_dict())

@self.route('/reload', methods=['POST'])
@self.route('/reload', methods=['POST'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:
json_data = await quart.request.json

Expand All @@ -51,7 +51,7 @@ async def _() -> str:
)
return self.success()

@self.route('/_debug/exec', methods=['POST'])
@self.route('/_debug/exec', methods=['POST'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:
if not constants.debug_mode:
return self.http_status(403, 403, "Forbidden")
Expand Down
24 changes: 23 additions & 1 deletion pkg/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,27 @@ async def reload(

await self.plugin_mgr.load_plugins()
await self.plugin_mgr.initialize_plugins()
case core_entities.LifecycleControlScope.PROVIDER.value:
self.logger.info("执行热重载 scope="+scope)

llm_model_mgr_inst = llm_model_mgr.ModelManager(self)
await llm_model_mgr_inst.initialize()
self.model_mgr = llm_model_mgr_inst

llm_session_mgr_inst = llm_session_mgr.SessionManager(self)
await llm_session_mgr_inst.initialize()
self.sess_mgr = llm_session_mgr_inst

llm_prompt_mgr_inst = llm_prompt_mgr.PromptManager(self)
await llm_prompt_mgr_inst.initialize()
self.prompt_mgr = llm_prompt_mgr_inst

llm_tool_mgr_inst = llm_tool_mgr.ToolManager(self)
await llm_tool_mgr_inst.initialize()
self.tool_mgr = llm_tool_mgr_inst

runner_mgr_inst = runnermgr.RunnerManager(self)
await runner_mgr_inst.initialize()
self.runner_mgr = runner_mgr_inst
case _:
pass
pass
1 change: 1 addition & 0 deletions pkg/core/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class LifecycleControlScope(enum.Enum):
APPLICATION = "application"
PLATFORM = "platform"
PLUGIN = "plugin"
PROVIDER = "provider"


class LauncherTypes(enum.Enum):
Expand Down
9 changes: 8 additions & 1 deletion web/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
重载插件
</v-list-item-title>
</v-list-item>

<v-list-item @click="reload('provider')">
<v-list-item-title>
重载 LLM 管理器
</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-list-item>
Expand Down Expand Up @@ -169,7 +175,8 @@ function openDocs() {
const reloadScopeLabel = {
'platform': "消息平台",
'plugin': "插件"
'plugin': "插件",
'provider': "LLM 管理器"
}
function reload(scope) {
Expand Down

0 comments on commit 97bb24c

Please sign in to comment.