Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add StructuredOutput component #4024

Merged
merged 34 commits into from
Oct 15, 2024
Merged

feat: add StructuredOutput component #4024

merged 34 commits into from
Oct 15, 2024

Conversation

ogabrielluiz
Copy link
Contributor

  • Refactor OpenAIModelComponent to use TableInput for output_schema and integrate build_model_from_schema.
  • Modify HierarchicalCrewComponent to use unpacking for base inputs.
  • Ensure consistent import statements across JSON files.
  • Improve error handling and logging for vector store operations.

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-4024.dmtpw4p5recq1.amplifyapp.com

@EDLLT
Copy link
Contributor

EDLLT commented Oct 5, 2024

  • Refactor OpenAIModelComponent to use TableInput for output_schema and integrate build_model_from_schema.
  • Modify HierarchicalCrewComponent to use unpacking for base inputs.
  • Ensure consistent import statements across JSON files.
  • Improve error handling and logging for vector store operations.

I'm assuming this also applies to this PR
#4021

@ogabrielluiz
Copy link
Contributor Author

It could but I'm considering something different. I'll push it as soon as I can. I'm considering building a component that builds the structured output using an llm.

@ogabrielluiz ogabrielluiz changed the title Update OpenAI model components feat: add StructuredOutput component Oct 7, 2024
@github-actions github-actions bot added the enhancement New feature or request label Oct 7, 2024
@ogabrielluiz ogabrielluiz marked this pull request as ready for review October 7, 2024 17:33
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Oct 7, 2024
@ogabrielluiz ogabrielluiz marked this pull request as draft October 7, 2024 17:50
@ogabrielluiz ogabrielluiz marked this pull request as ready for review October 7, 2024 17:51
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 7, 2024
@ogabrielluiz ogabrielluiz enabled auto-merge (squash) October 11, 2024 12:16
…l.py

- Implement various test cases to validate the functionality of build_model_from_schema.
- Test cases cover scenarios such as handling valid and empty schemas, managing unknown field types, and processing schemas with missing optional keys.
- Ensure proper handling of nested list and dict types, and verify the function's efficiency with large schemas.
- Confirm that the function raises exceptions for invalid input and handles duplicate field names correctly.
- Refactor `OpenAIModelComponent` to use `TableInput` for `output_schema` and integrate `build_model_from_schema`.
- Modify `HierarchicalCrewComponent` to use unpacking for base inputs.
- Ensure consistent import statements across JSON files.
- Improve error handling and logging for vector store operations.
- Implement `build_messages_and_runnable` to construct message lists and configure runnable models.
- Add `get_chat_result` to execute language models with input messages, supporting streaming and custom configurations.
- Handle exceptions with optional custom error messages.
- Implement various test cases to ensure correct functionality of StructuredOutputComponent.
- Test successful structured output generation, handling of unsupported language models, and correct output model building.
- Validate handling of multiple outputs, empty and invalid output schemas, and nested schemas.
- Include tests for large input values and invalid language model configurations.
Rename the test_base_model.py file to test_base_model_from_schema.py to better reflect its purpose of testing the build_model_from_schema function. This change improves code clarity and maintainability.
- Refactored `OpenAIModelComponent` to use `operator.ior` and `functools.reduce` for converting `output_schema` to a dictionary.
- Deprecated the `output_schema` field, updating its info to reflect the deprecation.
- Simplified the `_docs_to_data` method in `SplitTextComponent` for better readability.
- Updated import statements and removed unused imports across multiple JSON files.
@ogabrielluiz ogabrielluiz merged commit 2be7c56 into main Oct 15, 2024
27 checks passed
@ogabrielluiz ogabrielluiz deleted the update-openai branch October 15, 2024 21:41
diogocabral pushed a commit to headlinevc/langflow that referenced this pull request Nov 26, 2024
* Add utility functions to build Pydantic models from schema definitions

* Add unit tests for build_model_from_schema function in test_base_model.py

- Implement various test cases to validate the functionality of build_model_from_schema.
- Test cases cover scenarios such as handling valid and empty schemas, managing unknown field types, and processing schemas with missing optional keys.
- Ensure proper handling of nested list and dict types, and verify the function's efficiency with large schemas.
- Confirm that the function raises exceptions for invalid input and handles duplicate field names correctly.

* Refactor tests in `test_base_model.py` to improve type handling and error checking

* Refactor output schema handling to use TableInput and build_model_from_schema

* Update OpenAI model components and hierarchical crew setup

- Refactor `OpenAIModelComponent` to use `TableInput` for `output_schema` and integrate `build_model_from_schema`.
- Modify `HierarchicalCrewComponent` to use unpacking for base inputs.
- Ensure consistent import statements across JSON files.
- Improve error handling and logging for vector store operations.

* Add chat result model with message building and execution logic

- Implement `build_messages_and_runnable` to construct message lists and configure runnable models.
- Add `get_chat_result` to execute language models with input messages, supporting streaming and custom configurations.
- Handle exceptions with optional custom error messages.

* Add "table" to DIRECT_TYPES in constants.py

* Add support for DataFrame input validation in TableInput class

* Add StructuredOutputComponent for generating structured outputs from language models

* Enhance structured output component with improved input descriptions and schema naming

* Convert DataFrame to list of dictionaries in TableInput validation

* Remove pandas dependency and refactor schema handling in structured_output.py

* Remove 'default' field from structured output schema and update field initialization

* Add 'number' and 'text' types to type mapping and remove default value from field creation

* Enhance error handling in structured output building process

* Improve error message for non-BaseModel output in structured_output.py

* Add unit tests for StructuredOutputComponent in helpers module

- Implement various test cases to ensure correct functionality of StructuredOutputComponent.
- Test successful structured output generation, handling of unsupported language models, and correct output model building.
- Validate handling of multiple outputs, empty and invalid output schemas, and nested schemas.
- Include tests for large input values and invalid language model configurations.

* Update description for StructuredOutputComponent to clarify functionality

* Add default values and error handling for structured output in helpers

* Remove unused 'method' parameter from 'with_structured_output' in MockLanguageModel

* refactor: rename test_base_model.py to test_base_model_from_schema.py

Rename the test_base_model.py file to test_base_model_from_schema.py to better reflect its purpose of testing the build_model_from_schema function. This change improves code clarity and maintainability.

* Add type ignore comments to suppress type checking errors

* Add Generic typing to StructuredOutputComponent and fix method call

* Revert "Refactor output schema handling to use TableInput and build_model_from_schema"

This reverts commit 2e84a86.

* Deprecate JSON mode in OpenAIModel output schema documentation

* Remove unused Generic import and add type ignore comment in StructuredOutputComponent

* Refactor OpenAI model components and deprecate output schema

- Refactored `OpenAIModelComponent` to use `operator.ior` and `functools.reduce` for converting `output_schema` to a dictionary.
- Deprecated the `output_schema` field, updating its info to reflect the deprecation.
- Simplified the `_docs_to_data` method in `SplitTextComponent` for better readability.
- Updated import statements and removed unused imports across multiple JSON files.

* Add specific type ignore comments and update exception types in backend code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants