feat: 增加 MCP 研究模板保存工具
This commit is contained in:
@@ -7,6 +7,7 @@ from pydantic import Field, model_validator
|
||||
|
||||
from ..backtests.contracts import Candidate, SimulationSettings
|
||||
from ..catalog.contracts import CatalogFilters, Scope
|
||||
from ..research.workspace_contracts import TemplateSpec
|
||||
from ..schemas import Contract
|
||||
|
||||
Identifier = Annotated[str, Field(min_length=1, max_length=100)]
|
||||
@@ -74,6 +75,26 @@ class Control(Contract):
|
||||
idempotency_key: Identifier
|
||||
|
||||
|
||||
class CreateTemplate(Contract):
|
||||
template: TemplateSpec
|
||||
hypothesis: str = Field(min_length=1, max_length=10000)
|
||||
source_item_ids: list[RunId] = Field(min_length=1, max_length=20)
|
||||
reference: str | None = Field(default=None, max_length=200)
|
||||
idempotency_key: Identifier
|
||||
|
||||
@model_validator(mode="after")
|
||||
def research_template(self):
|
||||
self.template.name = self.template.name.strip()
|
||||
self.hypothesis = self.hypothesis.strip()
|
||||
if not self.template.name or not self.hypothesis or not self.template.expression.strip():
|
||||
raise ValueError("模板名称、表达式和研究假设不能为空")
|
||||
if self.template.category != "template":
|
||||
raise ValueError("此工具仅创建完整模板,不保存表达式片段")
|
||||
if len(set(self.source_item_ids)) != len(self.source_item_ids):
|
||||
raise ValueError("来源候选 ID 不能重复")
|
||||
return self
|
||||
|
||||
|
||||
class CatalogSearch(Contract):
|
||||
filters: CatalogFilters
|
||||
dataset_id: str | None = Field(default=None, min_length=1, max_length=200)
|
||||
|
||||
Reference in New Issue
Block a user