feat: integrate chatbox research with datasets and backtests
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user