* feat: Allow variables to be defined outside a Component
Fixes#4315
Modify `prepare_global_scope` function in `src/backend/base/langflow/utils/validate.py` to evaluate classes, functions, and variables defined outside the Component's class.
* **Function Changes:**
- Add evaluation of external classes using `ast.ClassDef`.
- Add evaluation of external functions using `ast.FunctionDef`.
- Add evaluation of external variables using `ast.Assign`.
* **Unit Tests:**
- Add tests in `src/backend/tests/unit/test_validate_code.py` to verify the evaluation of external classes, functions, and variables.
- Include tests for multiple external classes and external variables and functions.
---
For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/langflow-ai/langflow/issues/4315?shareId=XXXX-XXXX-XXXX-XXXX).
* [autofix.ci] apply automated fixes
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* ✨ (authContext.tsx): Add functionality to fetch global variables on authentication
🔧 (api.tsx): Replace universal-cookie import with react-cookie for consistency
🔧 (authStore.ts): Replace universal-cookie import with react-cookie for consistency
🔧 (use-get-global-variables.ts): Add check to only fetch global variables if user is authenticated
✨ (use-get-mutation-global-variables.ts): Add mutation function to fetch and update global variables
🔧 (authStore.ts): Replace universal-cookie import with react-cookie for consistency
* 📝 (endpoints.py): add feature_flags field to ConfigResponse schema
📝 (endpoints.py): modify get_config function to include feature_flags in the response
📝 (feature_flags.py): add mvp_components field to FeatureFlags settings
📝 (schemas.py): add feature_flags field to ConfigResponse schema
* ✨ (use-get-config.ts): Add feature_flags field to ConfigResponse interface to support feature flags in the application
🔧 (utilityStore.ts): Add featureFlags field and setFeatureFlags function to utilityStore to manage feature flags in the application
💡 (extraSidebarComponent/index.tsx): Use featureFlags from utilityStore to conditionally render components based on feature flags in ExtraSidebar component
* ♻️ (frontend/package-lock.json): remove extraneous flag from is-unicode-supported package to clean up unnecessary information
* ✨ (integration-side-bar.spec.ts): Add integration tests to ensure correct visibility of integrations in the sidebar based on the value of mvp_components.
* ✨ (integration-side-bar.spec.ts): update integration-side-bar tests to use feature_flags object for mvp_components flag for better readability and maintainability.
* ✨ (integration-side-bar.spec.ts): add a 4-second delay before making the API call to improve test reliability
* [autofix.ci] apply automated fixes
* Update src/backend/base/langflow/api/v1/schemas.py
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
* Update src/backend/base/langflow/api/v1/endpoints.py
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
* formata
* [autofix.ci] apply automated fixes
* ✨ (extraSidebarComponent/index.tsx): update featureFlags property access to use optional chaining for better error handling
📝 (stop-building.spec.ts): add ua-parser-js import to get user agent information and update control key based on user's operating system for better user experience. Also, refactor code to improve readability and add comments for better understanding.
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
The Loguru FileSink is blocking so it is bad to use it in the event loop.
Use instead an AsyncSink wrapping the FileSink to delegate the log writing to the default thread pool.
NB: when the AsyncFileSink is used, logs produced outside of the event loop are not written to the file.
* Fix issues with use of async
* Update src/backend/base/langflow/custom/custom_component/component.py
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
---------
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
* Remove unnecessary use of 'client' fixture in test_superuser
* Remove unnecessary use of 'usefixtures' decorator in test files
* Update test fixtures to improve test duration tracking
* Remove unnecessary 'client' fixture from test cases
* fix: Add missing inputs for HuggingFace model component and include pytest
- Added missing inputs to the HuggingFace model component.
- Implemented pytest to ensure the inputs are correctly handled.
* remove print statement
* Refine subflow field filtering to include '|' character check
* Add resource cleanup in test_components_path to ensure proper closure
* Remove unnecessary try-finally block in test_cli.py
* Remove unused pytest fixture decorator from test_components_path function
* Update test duration tracking in backend tests
* Enhance Component Input Handling and Add Unit Tests
Enhance component input handling and add unit tests for mixed input scenarios.
* [autofix.ci] apply automated fixes
* fix: handle JSON serialization for lists and dicts in _process_connection_or_parameters
- Updated the _process_connection_or_parameters function to handle lists and dictionaries properly.
- Ensured that each element in a list is checked for serializability and converted to a string if necessary.
- Added logic to convert dictionaries to JSON strings, handling non-serializable contents by converting them to strings.
- This change prevents JSON serialization errors when processing component parameters.
* reverting the changes
* [autofix.ci] apply automated fixes
* Update component.py
updates _process_connection_or_parameters to handles situations where the list is not all component.
Also handles any serialisation isseus caused by _process_connection_or_parameters
* [autofix.ci] apply automated fixes
* Update component.py
update make sure it is not a list str | int | float | bool | type(None)
Serialisation removed
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
* Refactor `recursive_serialize_or_str` function into a separate module
- Moved the `recursive_serialize_or_str` function from `schema.py` to a new `serialize.py` module for better modularity and reusability.
- Updated imports in `data.py`, `artifact.py`, and `schema.py` to reflect the new location of the `recursive_serialize_or_str` function.
- Enhanced the `recursive_serialize_or_str` function to handle `datetime` objects by converting them to ISO format.
* Enhance data serialization with recursive handling in `to_json` method
---------
Co-authored-by: Edwin Jose <edwin.jose@datastax.com>
Implement conditional tool output handling
- Updated `component.py` to check for `FEATURE_FLAGS.add_toolkit_output` and call `_append_tool_output` if the component has the `add_tool_output` attribute set to True.
- Ensured that the tool output behavior is correctly managed based on feature flags and component attributes in `custom_component.py`.
* updating components to access secret key with new method
* [autofix.ci] apply automated fixes
* 📝 (text_embedder.py): Add error messages as constants for better error handling and readability
📝 (text_embedder.py): Improve error handling and validation for embedding model and text content
📝 (text_embedder.py): Ensure proper protocol for the base URL in the embedding model client
📝 (text_embedder.py): Validate the output of embeddings and handle exceptions with logging
📝 (text_embedder.py): Refactor code to encapsulate results in a Data object and update status accordingly
📝 (similarity.spec.ts): Add a delay before clicking the button to run the text output test for better synchronization
* uv fix
* [autofix.ci] apply automated fixes
* 📝 (text_embedder.py): refactor error messages to use inline strings for better readability and maintainability
🐛 (text_embedder.py): fix issue with extracting the first element from embeddings list to ensure correct data handling
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Eric Hare <ericrhare@gmail.com>
* Start on big langchain dep upgrade
* Update pyproject.toml
* add new lock
* Rebase on post1 changes
---------
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
Update Azure OpenAI API versions and improve version selection
This PR updates the `AZURE_OPENAI_API_VERSIONS` list in the `AzureChatOpenAIComponent` class to include the latest GA and preview versions of the Azure OpenAI API. It also improves the default version selection logic.
Changes:
- Updated `AZURE_OPENAI_API_VERSIONS` list:
- Added the latest GA version: "2024-06-01"
- Added recent preview versions: "2024-07-01-preview", "2024-08-01-preview", "2024-09-01-preview", "2024-10-01-preview"
- Removed older versions that are no longer relevant
- Reordered the list to prioritize newer versions
- Improved the `api_version` DropdownInput:
- Now sorts options in reverse chronological order
- Default value now selects the latest non-preview version, falling back to the first version if all are preview
The updated list now reflects the most current API versions as of the latest documentation update, and the improved selection logic ensures users are presented with the most appropriate default version.
* Some fixes for ruff rules preview mode
* Fix mypy error
* More Annotated[] types for fastapi endpoints
* Use type aliases for Depends(get_session) and Depends(get_current_active_user)
* 📝 (utils.py): Add Query import and custom_params function to handle custom pagination parameters
📝 (flows.py): Update read_flows function to handle get_all flag and add error handling for missing folders
📝 (folders.py): Add custom_params dependency to read_folder endpoint for custom pagination handling
📝 (model.py): Remove PaginatedFlowResponse class as it is no longer used, add FlowHeader class to represent flow headers without data
✨ (test_database.py): Add pagination support for reading flows with different parameters to improve testing coverage and flexibility.
✅ (test_database.py): add unit tests for reading folders with different scenarios such as pagination, flows, search, and component filter to ensure proper functionality and data retrieval.
* 📝 (utils.py): Add constants MAX_PAGE_SIZE and MIN_PAGE_SIZE for better readability and maintainability
📝 (flows.py): Update get_all parameter default value to True for backward compatibility with frontend
📝 (flows.py): Update error message formatting for clarity
📝 (model.py): Update comments for folder_id, is_component, endpoint_name, and description fields for clarity
* ✨ (test_database.py): Simplify test functions by removing unnecessary parameters and code duplication to improve readability and maintainability.
* formatter
* [autofix.ci] apply automated fixes
* ruff fix
* [autofix.ci] apply automated fixes
---------
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
🔄 (constants.py): refactor sidebar categories list to improve readability and maintainability by removing unnecessary properties and formatting the dictionary entries for consistency.
* ✨ (endpoints.py): Add new endpoint to retrieve sidebar categories for the frontend application.
* 📝 (schemas.py): add SidebarCategory and SidebarCategoriesResponse models to define sidebar categories and response structure for API endpoint.
* ✨ (constants.py): Add sidebar categories with display names, names, icons, and beta status for different components to enhance the user interface and navigation experience.
* 📝 (constants.py): Update icons names to use proper casing for consistency and clarity in the code.