!28 Merge branch 'dev' into branch-statement-button
Merge pull request !28 from 王瑞雪/branch-statement-button
This commit is contained in:
19 files changed
+346
-4
No files matched your search
@@ -12,7 +12,7 @@ from flask import Blueprint
|
||||
chat_bp = Blueprint('chat', __name__)
|
||||
|
||||
# 子模块导入时在同一 Blueprint 上注册原有 URL。
|
||||
from . import assets, completions, directory, feedback, previews, sessions, uploads # noqa: E402, F401
|
||||
from . import assets, capability_list, completions, directory, feedback, previews, sessions, uploads # noqa: E402, F401
|
||||
from .shared import ( # noqa: E402, F401
|
||||
CHAT_USER_ATTACHMENT_LIMIT,
|
||||
CHAT_USER_ATTACHMENT_MAX_SIZE,
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
api/chat/capability_list.py
|
||||
|
||||
用途:聊天端「知识库内容清单」查询接口,作为知识库未命中兜底回复按钮的数据源。
|
||||
依赖:chat.shared(公共上下文与异常)、chat_bp、services.chat.capability_list。
|
||||
逻辑:GET /api/chat/capability-list?agent_id=...,经 require_agent_permission 鉴权后
|
||||
返回常用问题中该应用「能力清单条目」的标准答案;未配置时抛 404 业务错误。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from .shared import * # noqa: F403
|
||||
from . import chat_bp
|
||||
from app.services.chat.capability_list import get_agent_capability_list
|
||||
|
||||
|
||||
@chat_bp.route('/capability-list', methods=['GET'])
|
||||
@require_agent_permission
|
||||
def get_capability_list():
|
||||
"""
|
||||
获取当前应用的知识库内容清单。
|
||||
用途:AI 回复命中知识库未命中兜底语句时,前端【知识库内容清单】按钮点击后调用。
|
||||
核心逻辑:
|
||||
1. require_agent_permission 从 query 读取 agent_id 并校验用户对该应用的访问权限;
|
||||
2. 委托 services.chat.capability_list 返回「能力清单条目」标准答案;
|
||||
3. 未配置时抛 code=CHAT.CAPABILITY_LIST_NOT_FOUND(404),前端按错误码本地化提示。
|
||||
参数约束:agent_id 必须来自当前会话路由(当前聊天应用),禁止跨应用探测他人条目。
|
||||
"""
|
||||
agent = getattr(g, 'current_agent', None)
|
||||
if agent is None:
|
||||
raise AppError(code='SYSTEM.INTERNAL_ERROR', message='Missing agent context', http_status=500)
|
||||
return jsonify(get_agent_capability_list(agent))
|
||||
Reference in new issue
Block a user