51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""
|
||
backend/app/services/chat/intent_routes/text2sql.py
|
||
|
||
用途:固资 Text2SQL Intent 快路径注册。
|
||
依赖:text2sql、chat.intent_route_registry、agent_registry.resolver。
|
||
逻辑:由 load_builtin_intent_routes 调用 register();match 读 capabilities.erp_kb + kb_type 标签。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from app.services.chat.intent_route_registry import (
|
||
ChatIntentRouteContext,
|
||
ChatIntentRouteHandler,
|
||
register_chat_intent_route,
|
||
)
|
||
|
||
# 与前端 chat kb 选项 label 一致;仅在本 route 注册文件定义。
|
||
ERP_KB_TYPE_LABEL = 'ERP知识库'
|
||
|
||
|
||
def _match(ctx: ChatIntentRouteContext) -> bool:
|
||
from app.services.agent_registry.resolver import agent_has_erp_kb
|
||
|
||
if not agent_has_erp_kb(ctx.agent):
|
||
return False
|
||
return str(ctx.kb_type or '').strip() == ERP_KB_TYPE_LABEL
|
||
|
||
|
||
def _stream(ctx: ChatIntentRouteContext):
|
||
from app.services.text2sql import Text2SQLService
|
||
|
||
return Text2SQLService.stream_chat(
|
||
ctx.query,
|
||
ctx.user,
|
||
ctx.agent,
|
||
ctx.external_conversation_id,
|
||
session_id=ctx.session_id,
|
||
)
|
||
|
||
|
||
def register() -> ChatIntentRouteHandler:
|
||
"""注册 text2sql 快路径 handler。"""
|
||
return register_chat_intent_route(ChatIntentRouteHandler(
|
||
key='text2sql',
|
||
label='Text2SQL / 固资',
|
||
description='命中固资 Text2SQL 或 ERP 知识库特化意图时走 SQL 快路径',
|
||
priority=50,
|
||
match=_match,
|
||
stream=_stream,
|
||
))
|