feat: add utility to insert code field into build config dictionary (#8933)
feat: add code field to build configuration in custom component update if it was removed - Introduced `add_code_field_to_build_config` utility function to enhance build configuration with a code field. - Updated `custom_component_update` to conditionally add the code field if it is not already present, improving component customization capabilities. Co-authored-by: Edwin Jose <edwin.jose@datastax.com>
This commit is contained in:
parent
76fbcf4d55
commit
70f18bcb89
2 changed files with 24 additions and 1 deletions
|
|
@ -27,7 +27,12 @@ from langflow.api.v1.schemas import (
|
|||
UploadFileResponse,
|
||||
)
|
||||
from langflow.custom.custom_component.component import Component
|
||||
from langflow.custom.utils import build_custom_component_template, get_instance_name, update_component_build_config
|
||||
from langflow.custom.utils import (
|
||||
add_code_field_to_build_config,
|
||||
build_custom_component_template,
|
||||
get_instance_name,
|
||||
update_component_build_config,
|
||||
)
|
||||
from langflow.events.event_manager import create_stream_tokens_event_manager
|
||||
from langflow.exceptions.api import APIException, InvalidChatInputError
|
||||
from langflow.exceptions.serialization import SerializationError
|
||||
|
|
@ -727,6 +732,8 @@ async def custom_component_update(
|
|||
field_value=code_request.field_value,
|
||||
field_name=code_request.field,
|
||||
)
|
||||
if "code" not in updated_build_config:
|
||||
updated_build_config = add_code_field_to_build_config(updated_build_config, code_request.code)
|
||||
component_node["template"] = updated_build_config
|
||||
|
||||
if isinstance(cc_instance, Component):
|
||||
|
|
|
|||
|
|
@ -398,6 +398,22 @@ def add_code_field(frontend_node: CustomComponentFrontendNode, raw_code):
|
|||
return frontend_node
|
||||
|
||||
|
||||
def add_code_field_to_build_config(build_config: dict, raw_code: str):
|
||||
build_config["code"] = Input(
|
||||
dynamic=True,
|
||||
required=True,
|
||||
placeholder="",
|
||||
multiline=True,
|
||||
value=raw_code,
|
||||
password=False,
|
||||
name="code",
|
||||
advanced=True,
|
||||
field_type="code",
|
||||
is_list=False,
|
||||
).model_dump()
|
||||
return build_config
|
||||
|
||||
|
||||
def build_custom_component_template_from_inputs(
|
||||
custom_component: Component | CustomComponent, user_id: str | UUID | None = None
|
||||
):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue