Update frontend template with values from raw
template
This commit is contained in:
parent
344f761b57
commit
384d42fea4
1 changed files with 14 additions and 7 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import TYPE_CHECKING, List
|
from typing import TYPE_CHECKING, List
|
||||||
|
|
||||||
|
from langflow.services.deps import get_settings_service
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from langflow.services.database.models.flow.model import Flow
|
from langflow.services.database.models.flow.model import Flow
|
||||||
|
|
||||||
|
|
@ -71,9 +73,13 @@ def update_frontend_node_with_template_values(frontend_node, raw_template_data):
|
||||||
|
|
||||||
return frontend_node
|
return frontend_node
|
||||||
|
|
||||||
|
|
||||||
def is_valid_data(frontend_node, raw_template_data):
|
def is_valid_data(frontend_node, raw_template_data):
|
||||||
"""Check if the data is valid for processing."""
|
"""Check if the data is valid for processing."""
|
||||||
return frontend_node and "template" in frontend_node and raw_template_data and hasattr(raw_template_data, 'template')
|
return (
|
||||||
|
frontend_node and "template" in frontend_node and raw_template_data and hasattr(raw_template_data, "template")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def update_template_values(frontend_template, raw_template):
|
def update_template_values(frontend_template, raw_template):
|
||||||
"""Updates the frontend template with values from the raw template."""
|
"""Updates the frontend template with values from the raw template."""
|
||||||
|
|
@ -83,6 +89,7 @@ def update_template_values(frontend_template, raw_template):
|
||||||
|
|
||||||
update_template_field(frontend_template, key, value_dict)
|
update_template_field(frontend_template, key, value_dict)
|
||||||
|
|
||||||
|
|
||||||
def update_template_field(frontend_template, key, value_dict):
|
def update_template_field(frontend_template, key, value_dict):
|
||||||
"""Updates a specific field in the frontend template."""
|
"""Updates a specific field in the frontend template."""
|
||||||
template_field = frontend_template.get(key)
|
template_field = frontend_template.get(key)
|
||||||
|
|
@ -100,11 +107,11 @@ def update_template_field(frontend_template, key, value_dict):
|
||||||
template_field["file_path"] = file_path_value
|
template_field["file_path"] = file_path_value
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_file_path_value(file_path):
|
def get_file_path_value(file_path):
|
||||||
"""Get the file path value if the file exists, else return empty string."""
|
"""Get the file path value if the file exists, else return empty string."""
|
||||||
return file_path if Path(file_path).exists() else ""
|
settings_service = get_settings_service()
|
||||||
|
|
||||||
|
return file_path if Path(file_path).exists() and settings_service.settings.CONFIG_DIR in file_path else ""
|
||||||
|
|
||||||
|
|
||||||
def validate_is_component(flows: List["Flow"]):
|
def validate_is_component(flows: List["Flow"]):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue