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

Refactor prompt validation and code processing in Component and PromptComponent classes #2264

Merged
merged 10 commits into from
Jun 23, 2024

Conversation

ogabrielluiz
Copy link
Contributor

Adds a post_code_processing method that runs right after the component code is validated. The previous logic was moved into the Component class and classes that override this method should call the super() class almost always.

Components can now define post validation logic such as setting values dynamically when updated.

This PR also fixes the PromptComponent not being allowed to update its code.

Additionally, refactor the prompt validation process in the validate.py.

Copy link

vercel bot commented Jun 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langflow ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 23, 2024 0:42am

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 22, 2024
@dosubot dosubot bot added bug Something isn't working javascript Pull requests that update Javascript code labels Jun 22, 2024
@ogabrielluiz ogabrielluiz changed the title Refactor prompt validation and code processing in Component and PromptComponent classes" Refactor prompt validation and code processing in Component and PromptComponent classes Jun 22, 2024
Copy link
Member

@italojohnny italojohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 22, 2024
ogabrielluiz and others added 9 commits June 22, 2024 21:38
Refactor the prompt validation process in validate.py to improve code readability and maintainability. The changes include:

- Update the import statement for process_prompt_template in api_utils.py.
- Remove unused imports from api_utils.py.
- Simplify the post_validate_prompt function by removing unnecessary conditional statements.
- Replace the validate_prompt function call with process_prompt_template in post_validate_prompt.

These changes enhance the efficiency and organization of the prompt validation process.
When updating the Component code in GenericNode, handle any errors that occur. If an error occurs, display an error message with instructions to report the issue on Discord or GitHub. This improves the error handling and user experience when updating the Component code.
Refactor the post_code_validation method in the Component class to improve code readability and maintainability. The changes include:

- Rename the parameters to better reflect their purpose.
- Update the function documentation to provide a clear explanation of the method's purpose.
- Remove unnecessary comments and whitespace.
- Improve variable naming for better clarity.

These changes enhance the overall quality of the code and make it easier to understand and maintain.
Update the return type of the build_custom_component_template function in utils.py to include the possibility of returning a Component object. This change ensures that the function can handle both CustomComponent and Component objects, improving flexibility and compatibility.
The post_code_validation method in the Component class has been renamed to post_code_processing to better reflect its purpose. This change improves code clarity and maintainability.
Refactor the post_code_processing method in the PromptComponent class to improve code readability and maintainability. The changes include:

- Import the process_prompt_template function from langflow.base.prompts.api_utils.
- Import the update_template_values function from langflow.template.utils.
- Call the process_prompt_template function to update the template value.
- Update the frontend_node with any values set in the current_build_config.
- Remove unnecessary comments and whitespace.

These changes enhance the overall quality of the code and make it easier to understand and maintain.
@ogabrielluiz ogabrielluiz merged commit a9b2f5f into dev Jun 23, 2024
11 of 18 checks passed
@ogabrielluiz ogabrielluiz deleted the fix_prompt_update branch June 23, 2024 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working javascript Pull requests that update Javascript code lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants