Files
group_xinghuo_jinrong/app/model/analyst_schemas.py
T
zhanghongyu_0626 8556da489a feat(analyst): Add sample and escalate functionality to analyst API
- Introduced new endpoints `/api/analyst/query/{trace_id}/sample` and `/api/analyst/escalate` for sampling query results and escalating issues to human analysts, respectively.
- Enhanced `AnalystAgent` to support sampling of SQL results based on trace ID and to handle escalation requests, improving user experience in error scenarios.
- Updated `analyst_schemas.py` to include `EscalateRequest` for structured escalation requests.
- Added corresponding frontend API calls and UI components to facilitate user interactions with the new features.
- Implemented unit tests to ensure the reliability of the new functionalities.

This update significantly enhances the analytical capabilities of the application, allowing users to retrieve detailed query samples and escalate issues effectively.
2026-09-11 15:18:56 +08:00

87 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""数据分析 Agent 请求/响应 Pydantic 模型(输出四件套,需求规格 §3 全局约定)。"""
from __future__ import annotations
from pydantic import BaseModel, Field
DISCLAIMER = (
"本内容仅为投资分析参考,不构成任何直接投资建议,不构成对任何产品的收益承诺,"
"据此操作风险自负,请谨慎对待。"
)
CUSTOMER_AI_RISK_NOTE = "AI 分析有风险,仅供参考。"
class ChatRequest(BaseModel):
question: str = Field(..., description="自然语言问题")
session_id: str | None = None
trace_id: str | None = None
interpret: bool = Field(
default=False,
description="true=问数后立即 LLM 解读;false=仅 SQL+表格(解读走 /interpret)",
)
class TableData(BaseModel):
columns: list[str] = Field(default_factory=list)
rows: list[list] = Field(default_factory=list)
class Meta(BaseModel):
exec_ms: int = 0
row_count: int = 0
cache_hit: bool = False
template_hit: bool = False
template_key: str | None = None
data_as_of: str | None = None
source: str = ""
cost_est: float = 0.0
class InterpretRequest(BaseModel):
"""按需解读:上下文仅本轮问数快照(看图说话)。"""
question: str
status: str
answer: str = ""
table: TableData = Field(default_factory=TableData)
sql: str = ""
trace_id: str | None = None
meta: Meta = Field(default_factory=Meta)
class AnalystResponse(BaseModel):
"""统一输出四件套 + 状态/错误信息。"""
answer: str = ""
table: TableData = Field(default_factory=TableData)
sql: str = ""
meta: Meta = Field(default_factory=Meta)
disclaimer: str = DISCLAIMER
status: str = "success" # success / clarify / deny / degrade / error / escalate
error_code: str | None = None
suggestions: list[str] | None = Field(
default=None, description="权限拒绝时的可查范围引导(D-08)"
)
trace_id: str | None = None
class AssetCreateRequest(BaseModel):
"""沉淀资产(D-11):few_shot / dict / template。"""
kind: str = Field(..., description="few_shot / dict / template")
payload: dict = Field(default_factory=dict)
class EscalateRequest(BaseModel):
"""问数失败一键转人工(N-07)。"""
trace_id: str = Field(..., min_length=1, max_length=64)
question: str = Field(default="", max_length=2000)
reason: str = Field(default="", max_length=500)
class SampleRequest(BaseModel):
"""抽样明细(N-03)。"""
limit: int = Field(default=5, ge=1, le=20)