feat: Enhance StructuredOutputComponent and add trustcall dependency (#7249)

* chore: Add trustcall dependency to pyproject.toml

* fix: Update bind_tools method to include optional tool_choice parameter for enhanced flexibility in tool binding

* refactor: Update StructuredOutputComponent to utilize create_extractor for structured output and enhance result handling

* Replaced direct call to with_structured_output with create_extractor for improved flexibility.
* Added handling for "responses" in result to ensure proper data extraction.
* Introduced is_last_pydantic_output_parser method to check parser type in structured output processing.

* test: Add comprehensive tests for StructuredOutputComponent with OpenAI and NVIDIA models

* Implemented multiple test cases for StructuredOutputComponent using real OpenAI and NVIDIA models.
* Added tests for simple, complex, and nested schemas to validate structured output extraction.
* Included error handling tests to ensure proper response to model limitations and API errors.
* Utilized pytest for conditional test execution based on environment variables for API keys.

* refactor: Update JSON starter projects to include StructuredOutputComponent with enhanced input and output handling

* Integrated StructuredOutputComponent into Financial Report Parser and Portfolio Website Code Generator starter projects.
* Updated input fields to include detailed descriptions and requirements for structured output generation.
* Ensured consistent schema definitions and improved error handling for model limitations.
* Enhanced documentation for better clarity on component usage and expected outputs.

* [autofix.ci] apply automated fixes

* refactor: Remove unused PydanticOutputParser method from StructuredOutputComponent

* Deleted is_last_pydantic_output_parser method as it was no longer necessary for structured output processing.
* Cleaned up the code to enhance maintainability and readability.

* refactor: Update JSON starter projects to enhance StructuredOutputComponent integration

* Refactored Financial Report Parser and Portfolio Website Code Generator to streamline the StructuredOutputComponent.
* Removed unused PydanticOutputParser method to improve code clarity and maintainability.
* Enhanced input descriptions and requirements for structured output generation.
* Improved error handling and documentation for better user guidance.

* [autofix.ci] apply automated fixes

* refactor: Simplify response handling in StructuredOutputComponent

* Updated the response extraction logic to use the walrus operator for cleaner code.
* Improved readability by replacing the previous conditional check with a more concise approach.
* Ensured consistent handling of structured output results.

* [autofix.ci] apply automated fixes

* refactor: Remove unnecessary TYPE_CHECKING import and simplify type casting in StructuredOutputComponent

* Eliminated the TYPE_CHECKING import for improved clarity.
* Simplified the type casting of the language model in the response extraction logic.
* Enhanced code readability and maintainability.

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes

* refactor: reorder response handling in StructuredOutputComponent for clarity

* refactor: unify StructuredOutputComponent code across multiple starter projects for consistency

* Standardized the implementation of StructuredOutputComponent in Financial Report Parser, Image Sentiment Analysis, Market Research, and Portfolio Website Code Generator.
* Enhanced code clarity and maintainability by ensuring uniformity in input and output definitions across these components.

* refactor: update build_structured_output method in StructuredOutputComponent to include text_key

* Modified the build_structured_output method to return a Data object with a text_key for improved clarity in output structure.
* Ensured consistency across various starter projects by aligning the output format of StructuredOutputComponent.

* [autofix.ci] apply automated fixes

* 🔧 (structured_output.py): refactor create_extractor function to support structured data extraction in a specific format specified by schema_name
💡 (structured_output.py): add tool_description variable to provide a description for the structured data extraction tool

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes (attempt 2/3)

* ♻️ (structured_output.py): refactor code to simplify the creation of extractor with tools parameter and remove unnecessary tool_description and schema_name variables.

* [autofix.ci] apply automated fixes

*  (structured_output.py): enhance documentation by adding a dynamic docstring to the output model creation, improving clarity on the schema's purpose.

*  (structured_output.py): update structured output component across multiple starter projects to enhance consistency and clarity in output schema definitions. Improved documentation and dynamic docstring integration for better understanding of the structured data extraction process.

* 🔧 (typescript_test.yml): enhance test command by adding retries to Playwright tests for improved stability and reliability during CI runs. Cleaned up whitespace for better readability.

* feat: add sample resume for testing and update test to use new file

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Cristhian Zanforlin Lousa <cristhian.lousa@gmail.com>
This commit is contained in:
Gabriel Luiz Freitas Almeida 2025-04-02 15:50:28 -03:00 committed by GitHub
commit 43bdfdc7ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 350 additions and 19 deletions

View file

@ -155,7 +155,7 @@ jobs:
fi
echo "Fixed suites: $SUITES"
fi
TAGS=()
if echo "$SUITES" | jq -e 'contains(["components"])' > /dev/null; then
TAGS+=("@components")
@ -312,11 +312,11 @@ jobs:
command: |
cd src/frontend
echo 'Running tests with pattern: ${{ needs.determine-test-suite.outputs.test_grep }}'
npx playwright test ${{ inputs.tests_folder }} ${{ needs.determine-test-suite.outputs.test_grep }} --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --list
npx playwright test ${{ inputs.tests_folder }} ${{ needs.determine-test-suite.outputs.test_grep }} --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --list --retries=3
# echo command before running
echo "npx playwright test ${{ inputs.tests_folder }} ${{ needs.determine-test-suite.outputs.test_grep }} --trace on --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --workers 2"
echo "npx playwright test ${{ inputs.tests_folder }} ${{ needs.determine-test-suite.outputs.test_grep }} --trace on --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --workers 2 --retries=3"
npx playwright test ${{ inputs.tests_folder }} ${{ needs.determine-test-suite.outputs.test_grep }} --trace on --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --workers 2
npx playwright test ${{ inputs.tests_folder }} ${{ needs.determine-test-suite.outputs.test_grep }} --trace on --shard ${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --workers 2 --retries=3
- name: Upload Test Results
if: always()