Require label lists only on success.
This commit is contained in:
1 parent
28e3b5bfb9
commit
9d0e40cc4f
3 files changed
+62
-8
No files matched your search
@@ -12,7 +12,7 @@ from pathlib import Path
|
||||
|
||||
from google import genai
|
||||
from google.genai import types
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
||||
|
||||
from copienator import configuration as config
|
||||
from copienator.gemini_config import fresh_seed, thinking_config
|
||||
@@ -166,7 +166,23 @@ class BoxItem(BaseModel):
|
||||
box_2d: list[int] = Field(description="Bounding box coordinates (e.g., [ymin, xmin, ymax, xmax])")
|
||||
label: str = Field(description="The label associated with the specific box")
|
||||
|
||||
def _require_success_fields(schema: dict) -> None:
|
||||
"""Mirror the conditional payload validators in the schema sent to Gemini."""
|
||||
required = ["list"]
|
||||
if "name" in schema["properties"]:
|
||||
required.append("name")
|
||||
schema["anyOf"] = [
|
||||
{"required": required},
|
||||
{"required": ["error"],
|
||||
"properties": {"error": {"type": "string", "enum": ["insufficient_crop"]}}},
|
||||
{"required": ["upside_down_pages"],
|
||||
"properties": {"upside_down_pages": {"type": "array", "minItems": 1}}},
|
||||
]
|
||||
|
||||
|
||||
class LabelData(BaseModel):
|
||||
model_config = ConfigDict(json_schema_extra=_require_success_fields)
|
||||
|
||||
upside_down_pages: typing.List[typing.Annotated[int, Field(strict=True, ge=1)]] = Field(
|
||||
default_factory=list,
|
||||
description='1-based column numbers in this image that appear upside down (180 degrees)',
|
||||
|
||||
Reference in new issue
Block a user