feat: integrate chatbox research with datasets and backtests

This commit is contained in:
yuxuanhui
2026-09-08 12:43:00 +08:00
parent 43336ad960
commit aef8e1d310
37 changed files with 1421 additions and 42 deletions
+12
View File
@@ -8,6 +8,8 @@ from uuid import uuid4
from pydantic_ai.messages import ToolReturnPart, UserPromptPart
from pydantic_ai.models.function import DeltaToolCall, FunctionModel
from tests.research_fake import research_step
async def fake_stream(messages, info):
latest = max(
@@ -17,6 +19,16 @@ async def fake_stream(messages, info):
str(p.content) for m in messages[latest:] for p in m.parts if isinstance(p, UserPromptPart)
)
returns = [p for m in messages[latest:] for p in m.parts if isinstance(p, ToolReturnPart)]
if any(marker in text for marker in ("研究此输入", "自行选字段研究", "解读研究结果")):
step = research_step(
text, returns, [p for m in messages for p in m.parts if isinstance(p, ToolReturnPart)]
)
if isinstance(step, str):
yield step
else:
name, args = step
yield {0: DeltaToolCall(name=name, json_args=json.dumps(args), tool_call_id=uuid4().hex)}
return
if returns and returns[-1].tool_name == "prepare_backtest":
content = returns[-1].content
content = json.loads(content) if isinstance(content, str) else content