fix(capabilities): add explicit usage and finish_reason types to Output classes#100
Conversation
…ut classes Override usage and finish_reason field types in capability Output classes to ensure proper Pydantic serialization. Without explicit type annotations, Pydantic uses the base Usage/FinishReason schema (empty) instead of the capability-specific subclass fields.
Code Review SummaryThis PR addresses a real Pydantic serialization issue and the fix is correct. The changes properly ensure that capability-specific subclass fields are included in serialization. Overall, this is a solid fix with good scope and testing approach. ✅ Strengths
🔍 Code Quality Observations1. Consistency in Field DefinitionsThe changes follow a consistent pattern: usage: SpecificUsage = Field(default_factory=SpecificUsage)
finish_reason: SpecificFinishReason | None = NoneThis matches the base class signature in 2. Import AdditionsAll files correctly add 3. Type SafetyThe explicit type annotations improve type safety and IDE autocomplete, as tools can now properly infer the specific usage/finish_reason types rather than the base types. 💡 Potential Improvements1. Video Generation Missing
|
Summary
usageandfinish_reasonfield types in capability Output classes{})Changes
text-generation/io.py- AddTextGenerationUsageandTextGenerationFinishReasonto Outputimage-generation/io.py- AddImageGenerationUsageandImageGenerationFinishReasonto Outputvideo-generation/io.py- AddVideoGenerationUsageto Outputspeech-generation/io.py- AddSpeechGenerationUsageandSpeechGenerationFinishReasonto OutputTest plan
TextGenerationOutput.model_dump()includes usage fields