feat:完成大部分数据文件上传解析功能
This commit is contained in:
@@ -7,6 +7,7 @@ import json
|
||||
|
||||
from langchain_core.messages import HumanMessage
|
||||
|
||||
from app.agent.data_tools import DataContext
|
||||
from app.agent.screen_agent import AgentReply, get_screen_agent
|
||||
from app.agent.tools import ScreenAgentContext
|
||||
from app.processor.base import BaseNode
|
||||
@@ -53,7 +54,7 @@ class ScreenAgentNode(BaseNode):
|
||||
return updated_state
|
||||
|
||||
context = state["input_context"]
|
||||
agent = await get_screen_agent()
|
||||
agent = await get_screen_agent(with_data=bool(context.data_files))
|
||||
result = await agent.ainvoke(
|
||||
{
|
||||
# 会话历史作为此前的对话消息,本次请求是最后一条用户消息
|
||||
@@ -64,7 +65,11 @@ class ScreenAgentNode(BaseNode):
|
||||
),
|
||||
]
|
||||
},
|
||||
context=ScreenAgentContext(screen=context.screen, catalog=catalog),
|
||||
context=ScreenAgentContext(
|
||||
screen=context.screen,
|
||||
catalog=catalog,
|
||||
data=DataContext(tuple(context.data_files)),
|
||||
),
|
||||
)
|
||||
if result.get("structured_response") is None:
|
||||
last = result["messages"][-1]
|
||||
|
||||
@@ -4,11 +4,15 @@
|
||||
"""
|
||||
|
||||
from app.schemas.base import JsonObject
|
||||
from app.schemas.data_file import RequestDataFile
|
||||
from app.schemas.input_context import InputContext
|
||||
|
||||
# 每张表在摘要里最多列出的列名,完整的列用 describe_data 查看
|
||||
SUMMARY_COLUMNS = 30
|
||||
|
||||
|
||||
def request_summary(context: InputContext) -> JsonObject:
|
||||
"""用户输入、澄清记录、编辑上下文、附件和大屏摘要"""
|
||||
"""用户输入、澄清记录、编辑上下文、附件、数据文件和大屏摘要"""
|
||||
nodes: list[JsonObject] = []
|
||||
for node in context.screen.nodes:
|
||||
# 图表标题帮助判断用户指的是哪个组件;没有 option 或标题格式不符时按无标题处理
|
||||
@@ -45,8 +49,32 @@ def request_summary(context: InputContext) -> JsonObject:
|
||||
for source in context.screen.dataSource
|
||||
],
|
||||
},
|
||||
# 数据文件的附件由 data_files 的 attached_this_turn 表示
|
||||
"attachments": [
|
||||
{key: item[key] for key in ("id", "kind", "name") if key in item}
|
||||
for item in context.attachments
|
||||
if item.get("kind") != "data_file"
|
||||
],
|
||||
"data_files": [_data_file(item) for item in context.data_files],
|
||||
}
|
||||
|
||||
|
||||
def _data_file(item: RequestDataFile) -> JsonObject:
|
||||
"""每个文件只给表名、label、行数和列名;列概况由 describe_data 按需查看"""
|
||||
tables: list[JsonObject] = []
|
||||
for table in item.tables:
|
||||
summary: JsonObject = {
|
||||
"table": table.table,
|
||||
"label": table.label,
|
||||
"rows": table.rows,
|
||||
"columns": [column.name for column in table.columns[:SUMMARY_COLUMNS]],
|
||||
}
|
||||
if len(table.columns) > SUMMARY_COLUMNS:
|
||||
summary["column_count"] = len(table.columns)
|
||||
tables.append(summary)
|
||||
return {
|
||||
"file_id": item.file_id,
|
||||
"name": item.name,
|
||||
"attached_this_turn": item.attached_this_turn,
|
||||
"tables": tables,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user