feat(py): add array, enum, and jsonl output formats for JS parity#4230
feat(py): add array, enum, and jsonl output formats for JS parity#4230
Conversation
f86a4d8 to
af67bfc
Compare
Summary of ChangesHello @yesudeep, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Python Genkit library by introducing three new output formats: Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces new output formats (array, enum, jsonl) to achieve feature parity with the JavaScript implementation, along with comprehensive documentation and unit tests. The changes also include improvements to how output configurations are handled and fixes for text accumulation in streaming responses. Overall, the changes are well-structured and enhance the functionality of the Genkit Python library.
Add missing output formats to achieve feature parity with the canonical JavaScript implementation: - **array**: Parses model output as a JSON array of objects. Uses `extract_items` for robust parsing of streaming chunks. - **enum**: Constrains model to output a single value from a predefined list. Useful for classification tasks. - **jsonl**: Parses newline-delimited JSON objects. Optimized for streaming scenarios where each object can be processed independently. CHANGELOG: - Add ArrayFormat, EnumFormat, and JsonlFormat implementations - Update FormatterConfig to match JS canonical behavior: - enum: content_type='text/enum', constrained=True - array: content_type='application/json', constrained=True - jsonl: content_type='application/jsonl' (unconstrained) - text: content_type='text/plain' (unconstrained) - Fix TextFormat.chunk_parser to return chunk.text (current chunk only) instead of accumulated_text, matching JS behavior - Fix GenerateResponseChunkWrapper.accumulated_text to correctly accumulate text from previous chunks - Update _aio.py to safely handle OutputConfig using getattr() since typing.py is auto-generated and may not have all fields - Add comprehensive documentation with format comparison table - Add unit tests for all new formats - Add format-demo sample demonstrating all five formats with pre-populated inputs: - generate_haiku_text (text format) - get_country_info_json (json format) - recommend_books_array (array format) - classify_sentiment_enum (enum format) - create_story_characters_jsonl (jsonl format)
af67bfc to
d527e38
Compare
Add missing output formats to achieve feature parity with the canonical
JavaScript implementation:
extract_itemsfor robust parsing of streaming chunks.list. Useful for classification tasks.
streaming scenarios where each object can be processed independently.
CHANGELOG:
instead of accumulated_text, matching JS behavior
accumulate text from previous chunks
typing.py is auto-generated and may not have all fields
pre-populated inputs: