feat(agent-office): 큐레이터 응답 검증 스키마 + 테스트
This commit is contained in:
41
agent-office/app/curator/schema.py
Normal file
41
agent-office/app/curator/schema.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from typing import List, Literal
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
|
||||
class Pick(BaseModel):
|
||||
numbers: List[int] = Field(min_length=6, max_length=6)
|
||||
risk_tag: Literal["안정", "균형", "공격"]
|
||||
reason: str = Field(max_length=80)
|
||||
|
||||
@field_validator("numbers")
|
||||
@classmethod
|
||||
def _check_numbers(cls, v):
|
||||
if len(set(v)) != 6:
|
||||
raise ValueError("numbers must be 6 unique integers")
|
||||
if any(n < 1 or n > 45 for n in v):
|
||||
raise ValueError("numbers must be within 1..45")
|
||||
return sorted(v)
|
||||
|
||||
|
||||
class Narrative(BaseModel):
|
||||
headline: str
|
||||
summary_3lines: List[str] = Field(min_length=3, max_length=3)
|
||||
hot_cold_comment: str = ""
|
||||
warnings: str = ""
|
||||
|
||||
|
||||
class CuratorOutput(BaseModel):
|
||||
picks: List[Pick]
|
||||
narrative: Narrative
|
||||
confidence: int = Field(ge=0, le=100)
|
||||
|
||||
|
||||
def validate_response(data: dict, candidate_numbers: List[List[int]]) -> CuratorOutput:
|
||||
out = CuratorOutput.model_validate(data)
|
||||
if len(out.picks) != 5:
|
||||
raise ValueError("picks must have exactly 5 sets")
|
||||
candidate_set = {tuple(sorted(c)) for c in candidate_numbers}
|
||||
for p in out.picks:
|
||||
if tuple(p.numbers) not in candidate_set:
|
||||
raise ValueError(f"pick {p.numbers} not in candidates")
|
||||
return out
|
||||
Reference in New Issue
Block a user