🚀 feat(CodeAreaModal): replace UpdateTemplate function with postCustomComponent function to send custom component code to the server
The UpdateTemplate function was not being used and was removed. The postCustomComponent function was added to send custom component code to the server. The CodeAreaModal component was updated to use the new postCustomComponent function instead of the UpdateTemplate function to send custom component code to the server.
This commit adds a new file called `extract_info_from_class.py` containing a `ClassCodeExtractor` class that can extract information (imports, class details and functions) from a Python class code. It also adds a function called `is_valid_class_template` that checks if a given Python class code matches a certain template. Additionally, the commit adds a new endpoint in the `/custom_component` route of `endpoints.py` that returns a dictionary of all `langchain` types created by a specific creator. Finally, the commit adds a new section to `types.py` named `template_node`, which describes a default dictionary that can be used to define a new node for Langflow's template editor.
refactor(codeAreaComponent): change template to nodeClass and setTemplate to setNodeClass to improve semantics
refactor(API): change UpdateTemplate function parameter from template to nodeClass to improve semantics
refactor(codeAreaModal): change template to nodeClass and setTemplate to setNodeClass to improve semantics and fix bug
refactor(types): add APIClassType to import and change APITemplateType to import in relevant files to improve semantics
fix(API): fix UpdateTemplate function return type to match the actual response
fix(vite.config.ts): add dynamic_node route to apiRoutes array to proxy requests to backend
This change updates an event parameter type in BuildTrigger to improve type safety. Specifically, an event parameter type was modified from 'any' to a more specific type to avoid invalid use of the event parameter.
The event name was changed from "node" to "message" to better reflect the nature of the data being sent. The data being sent is a message response from the server, not a node in the graph.
🐛 fix(buildTrigger): handle error response from server when starting a build
The ProgressBarComponent import was removed as it was not being used. The error handling was improved to handle the case where the server returns an error response when starting a build. The error message is now displayed to the user and the build state is reset.
🐛 fix(chat.py): fix StreamData class import statement
✨ feat(chat.py): add progress tracking and node building events to stream_build function
The unused import statement has been removed to improve code readability. The StreamData class import statement has been fixed to avoid errors. Progress tracking and node building events have been added to the stream_build function to provide more information to the user about the build process.
The StreamData model is added to represent the data that is streamed from the server. The __str__ method is added to improve the readability of the stream data by returning a formatted string that includes the event and data attributes.
The buildTrigger component was updated to use progress state instead of myValue to better represent the progress of the building process. This change allowed us to make improvements in the way progress is tracked, which will improve the user experience.
🐛 fix(chat.py): catch exception when building graph and yield error message
When the flow_id is invalid, the yield statement should return an error message instead of data. Additionally, when building the graph, an exception could occur, so we added a try-except block to catch any exceptions and yield an error message instead of data.
- The radial progress now displays the percentage value correctly.
- In the build trigger, we now properly handle the end of a stream event and fixed an issue with the RadialProgressComponent when isBuilding is true.
This commit adds a value state to the RadialProgress component, replacing the progressContext previously used. It also removes the progressContext, as it is no longer needed.
The version number has been updated from 0.1.4 to 0.1.5 to reflect the changes made in the package. This is a chore commit as it does not add any new features or fix any bugs, but rather updates the version number.
The conditional statement in the update_flow function was incorrect. The if statement was checking for the opposite of what was intended. The fix changes the if statement to check for the correct condition.
# Pull Request Description
## Summary
This Pull Request includes several code improvements, refactoring,
feature additions, and documentation updates mainly focused on enhancing
the functionality and maintainability of the codebase.
## Details
### Refactoring and Improvements:
- **Commit (5ea20aa) by @ogabrielluiz**: Unnecessary indentation in the
`getPythonCode` function within `constants.tsx` has been removed to
improve code readability.
- **Commit (6886828) by @ogabrielluiz**:
- Changed the `load_flow_from_json` function signature in `process.py`
to accept either a JSON file path or a JSON object.
- Updated the import statement for `Chain` in `base.py` to be more
explicit by importing it from `langchain.chains.base` instead of
`langflow.graph.vertex.types`.
- Removed a print statement from the `process_tweaks` function in
`process.py`.
- Added an optional `tweaks` parameter to the `load_flow_from_json`
function.
- Changed the return type of the `build` method in the `Graph` class
from `List[Vertex]` to `Chain`.
- **Commit (83c28dc) by @ogabrielluiz**: The `process_tweaks` function
in `process.py` has been refactored to improve readability and
maintainability. An `apply_tweaks` function was added to apply tweaks to
the node, and a `validate_input` function was added for input
validation. The function now raises a `ValueError` if the input is not
in the expected format.
- **Commit (11185af) by @ogabrielluiz**: Refactored the
`fix_memory_inputs` function in `process.py` to improve readability by
reducing nesting. The function now checks if the `langchain_object` has
a `memory` attribute and if it is not `None` before proceeding. The
try-except block was also refactored to reduce nesting.
- **Commit (f180fa6) by @ogabrielluiz**: The input parameter in
`process.py` has been changed to accept a `Path` object in addition to a
string or dictionary, improving the flexibility of the function and
allowing for easier file handling.
### Features:
- **Commit (8a5525f) by @ogabrielluiz**: The `getPythonCode` function in
`constants.tsx` now accepts a `tweaks` parameter which is used to
customize the behavior of the flow. A `buildTweaks` function generates
the `tweaks` object which is passed to the `load_flow_from_json`
function.
- **Commit (c5d6f48) by @ogabrielluiz**: Added a `build_and_install`
target to the `Makefile` to build the package and install it without
running it. This is useful for building and installing on a remote
server. Additionally, fixed the path to the `langflow.main` module in
the backend target of the `Makefile`.
### Documentation:
- **Commit (76a1265) by @ogabrielluiz**: Updated the Langflow API usage
example in `README.md` to reflect the new API endpoint URL. Added a new
optional `tweaks` parameter to the `run_flow` function for flow
customization and updated the example code accordingly.
### Other:
- **Commit (0dcd93e) by @lucaseduoli**: Added Discord and Twitter icons,
and GitHub stars.
- **Commit (0dcd93e) by @lucaseduoli**: Fixed the Twitter link.
The version number has been updated from 0.1.3 to 0.1.4. This is a chore commit as it does not introduce any new features or bug fixes, but rather updates the version number to reflect changes made in the package.