refactor: Add CustomComponentResponse model and update custom_component endpoint
This commit adds the CustomComponentResponse model to the schemas.py file, allowing the custom_component endpoint to return a structured response. The custom_component endpoint in the endpoints.py file has been updated to include the response_model parameter, specifying the CustomComponentResponse model. This ensures that the endpoint returns the built_frontend_node along with the type of the component_instance. These changes improve the consistency and clarity of the API response.
This commit is contained in:
parent
5aa6450a3c
commit
edc96718d7
2 changed files with 8 additions and 2 deletions
|
|
@ -11,6 +11,7 @@ from sqlmodel import Session, select
|
||||||
from langflow.api.v1.schemas import (
|
from langflow.api.v1.schemas import (
|
||||||
ConfigResponse,
|
ConfigResponse,
|
||||||
CustomComponentRequest,
|
CustomComponentRequest,
|
||||||
|
CustomComponentResponse,
|
||||||
InputValueRequest,
|
InputValueRequest,
|
||||||
ProcessResponse,
|
ProcessResponse,
|
||||||
RunResponse,
|
RunResponse,
|
||||||
|
|
@ -458,7 +459,7 @@ def get_version():
|
||||||
return {"version": version, "package": package}
|
return {"version": version, "package": package}
|
||||||
|
|
||||||
|
|
||||||
@router.post("/custom_component", status_code=HTTPStatus.OK)
|
@router.post("/custom_component", status_code=HTTPStatus.OK, response_model=CustomComponentResponse)
|
||||||
async def custom_component(
|
async def custom_component(
|
||||||
raw_code: CustomComponentRequest,
|
raw_code: CustomComponentRequest,
|
||||||
user: User = Depends(get_current_active_user),
|
user: User = Depends(get_current_active_user),
|
||||||
|
|
@ -468,7 +469,7 @@ async def custom_component(
|
||||||
built_frontend_node, component_instance = build_custom_component_template(component, user_id=user.id)
|
built_frontend_node, component_instance = build_custom_component_template(component, user_id=user.id)
|
||||||
if raw_code.frontend_node is not None:
|
if raw_code.frontend_node is not None:
|
||||||
built_frontend_node = component_instance.post_code_processing(built_frontend_node, raw_code.frontend_node)
|
built_frontend_node = component_instance.post_code_processing(built_frontend_node, raw_code.frontend_node)
|
||||||
return built_frontend_node
|
return CustomComponentResponse(data=built_frontend_node, type=component_instance.__class__.__name__)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/custom_component/update", status_code=HTTPStatus.OK)
|
@router.post("/custom_component/update", status_code=HTTPStatus.OK)
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,11 @@ class CustomComponentRequest(BaseModel):
|
||||||
frontend_node: Optional[dict] = None
|
frontend_node: Optional[dict] = None
|
||||||
|
|
||||||
|
|
||||||
|
class CustomComponentResponse(BaseModel):
|
||||||
|
data: dict
|
||||||
|
type: str
|
||||||
|
|
||||||
|
|
||||||
class UpdateCustomComponentRequest(CustomComponentRequest):
|
class UpdateCustomComponentRequest(CustomComponentRequest):
|
||||||
field: str
|
field: str
|
||||||
field_value: Optional[Union[str, int, float, bool, dict, list]] = None
|
field_value: Optional[Union[str, int, float, bool, dict, list]] = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue