feat: add dynamic outputs to Component (#4308)
* Refine condition to check for undefined value in use-handle-new-value hook * update mutateTemplate to use APIClassType * Refactor Component class to update inputs and validate outputs This commit refactors the Component class in the `component.py` file. It introduces two new methods: `update_inputs` and `run_and_validate_update_outputs`. The `update_inputs` method allows for updating the build configuration with new field values, while the `run_and_validate_update_outputs` method updates the frontend node and validates the outputs. Additionally, the `_validate_frontend_node` method is added to check if all outputs are valid. The `_set_output_types` method is modified to accept a list of outputs and set their return types. Overall, these changes improve the functionality and maintainability of the Component class. * Add dynamic output validation in API endpoint for component updates * Update build_config to store field_value under "value" key * Refactor: Convert dict values to list in _set_output_types call * Add type check for `cc_instance` before calling `run_and_validate_update_outputs` * Add DynamicOutputComponent with configurable outputs based on input * Add test for updating component outputs with dynamic code input * Refactor: Make get_dynamic_output_component_code asynchronous for improved performance --------- Co-authored-by: Edwin Jose <edwin.jose@datastax.com>
This commit is contained in:
parent
dd4a9f908c
commit
42cc1dacd2
9 changed files with 145 additions and 38 deletions
|
|
@ -1,5 +1,16 @@
|
|||
import asyncio
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from fastapi import status
|
||||
from httpx import AsyncClient
|
||||
from langflow.api.v1.schemas import UpdateCustomComponentRequest
|
||||
|
||||
|
||||
async def get_dynamic_output_component_code():
|
||||
return await asyncio.to_thread(
|
||||
Path("src/backend/tests/data/dynamic_output_component.py").read_text, encoding="utf-8"
|
||||
)
|
||||
|
||||
|
||||
async def test_get_version(client: AsyncClient):
|
||||
|
|
@ -23,3 +34,21 @@ async def test_get_config(client: AsyncClient):
|
|||
assert "auto_saving" in result, "The dictionary must contain a key called 'auto_saving'"
|
||||
assert "health_check_max_retries" in result, "The dictionary must contain a 'health_check_max_retries' key"
|
||||
assert "max_file_size_upload" in result, "The dictionary must contain a key called 'max_file_size_upload'"
|
||||
|
||||
|
||||
async def test_update_component_outputs(client: AsyncClient, logged_in_headers: dict):
|
||||
code = await get_dynamic_output_component_code()
|
||||
frontend_node: dict[str, Any] = {"outputs": []}
|
||||
request = UpdateCustomComponentRequest(
|
||||
code=code,
|
||||
frontend_node=frontend_node,
|
||||
field="show_output",
|
||||
field_value=True,
|
||||
template={},
|
||||
)
|
||||
response = await client.post("api/v1/custom_component/update", json=request.model_dump(), headers=logged_in_headers)
|
||||
result = response.json()
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
output_names = [output["name"] for output in result["outputs"]]
|
||||
assert "tool_output" in output_names
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue