feat: support image inputs in assistant tests
This commit is contained in:
+25
-8
@@ -143,20 +143,36 @@ ExpectedBehavior = Annotated[
|
||||
]
|
||||
|
||||
|
||||
class FixedInputTurn(CamelModel):
|
||||
id: str = Field(min_length=1, max_length=128)
|
||||
user_input: str = Field(min_length=1, max_length=20_000)
|
||||
behaviors: list[ExpectedBehavior] = Field(default_factory=list, max_length=100)
|
||||
class TestImageRef(CamelModel):
|
||||
asset_id: str = Field(min_length=1, max_length=40)
|
||||
filename: str = Field(default="image.jpg", max_length=255)
|
||||
width: int = Field(ge=1)
|
||||
height: int = Field(ge=1)
|
||||
size_bytes: int = Field(default=0, ge=0)
|
||||
|
||||
@field_validator("user_input")
|
||||
@field_validator("asset_id", "filename")
|
||||
@classmethod
|
||||
def strip_user_input(cls, value: str) -> str:
|
||||
def strip_image_text(cls, value: str) -> str:
|
||||
value = value.strip()
|
||||
if not value:
|
||||
raise ValueError("用户输入不能为空")
|
||||
raise ValueError("图片资源信息不完整")
|
||||
return value
|
||||
|
||||
|
||||
class FixedInputTurn(CamelModel):
|
||||
id: str = Field(min_length=1, max_length=128)
|
||||
user_input: str = Field(default="", max_length=20_000)
|
||||
image: TestImageRef | None = None
|
||||
behaviors: list[ExpectedBehavior] = Field(default_factory=list, max_length=100)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_input(self):
|
||||
self.user_input = self.user_input.strip()
|
||||
if not self.user_input and self.image is None:
|
||||
raise ValueError("用户输入和图片至少填写一项")
|
||||
return self
|
||||
|
||||
|
||||
class OverallCriterion(CamelModel):
|
||||
id: str = Field(min_length=1, max_length=128)
|
||||
type: Literal["llm"] = "llm"
|
||||
@@ -272,7 +288,7 @@ class TestCaseWrite(CamelModel):
|
||||
@model_validator(mode="after")
|
||||
def validate_mvp_definition(self):
|
||||
if self.input_mode != "fixed_script_text":
|
||||
raise ValueError("第一版只支持固定脚本 · 文字")
|
||||
raise ValueError("第一版只支持固定脚本 · 多模态")
|
||||
TestCaseDefinition(
|
||||
context_turns=self.context_turns,
|
||||
turns=self.turns,
|
||||
@@ -362,6 +378,7 @@ class BatchTurnResult(CamelModel):
|
||||
id: str
|
||||
index: int
|
||||
user_input: str
|
||||
image: TestImageRef | None = None
|
||||
assistant_reply: str
|
||||
tool_calls: list[BatchToolCallRecord] = Field(default_factory=list)
|
||||
runtime_records: list[dict[str, Any]] = Field(default_factory=list)
|
||||
|
||||
Reference in New Issue
Block a user