From 508c66cbaa039fe09af4a4a5aac3c4630191666d Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 23 Jun 2023 08:40:43 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(endpoints.py):=20make=20inpu?= =?UTF-8?q?ts=20and=20tweaks=20optional=20in=20process=5Fflow=20endpoint?= =?UTF-8?q?=20=F0=9F=90=9B=20fix(process.py):=20make=20inputs=20optional?= =?UTF-8?q?=20in=20process=5Fgraph=5Fcached=20function=20The=20inputs=20an?= =?UTF-8?q?d=20tweaks=20parameters=20in=20the=20process=5Fflow=20endpoint?= =?UTF-8?q?=20are=20now=20optional,=20which=20allows=20for=20more=20flexib?= =?UTF-8?q?ility=20in=20the=20API.=20The=20inputs=20parameter=20in=20the?= =?UTF-8?q?=20process=5Fgraph=5Fcached=20function=20is=20now=20optional,?= =?UTF-8?q?=20which=20prevents=20a=20ValueError=20from=20being=20raised=20?= =?UTF-8?q?when=20a=20Chain=20object=20is=20processed=20without=20inputs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/endpoints.py | 2 +- src/backend/langflow/processing/process.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/api/v1/endpoints.py b/src/backend/langflow/api/v1/endpoints.py index d48900117..c9d6e807e 100644 --- a/src/backend/langflow/api/v1/endpoints.py +++ b/src/backend/langflow/api/v1/endpoints.py @@ -27,7 +27,7 @@ def get_all(): @router.post("/process/{flow_id}", response_model=ProcessResponse) async def process_flow( flow_id: str, - inputs: dict, + inputs: Optional[dict] = None, tweaks: Optional[dict] = None, session: Session = Depends(get_session), ): diff --git a/src/backend/langflow/processing/process.py b/src/backend/langflow/processing/process.py index 69f8fbfea..abf7a00b8 100644 --- a/src/backend/langflow/processing/process.py +++ b/src/backend/langflow/processing/process.py @@ -82,7 +82,7 @@ def get_input_str_if_only_one_input(inputs: dict) -> Optional[str]: return list(inputs.values())[0] if len(inputs) == 1 else None -def process_graph_cached(data_graph: Dict[str, Any], inputs: dict): +def process_graph_cached(data_graph: Dict[str, Any], inputs: Optional[dict] = None): """ Process graph by extracting input variables and replacing ZeroShotPrompt with PromptTemplate,then run the graph and return the result and thought. @@ -99,6 +99,8 @@ def process_graph_cached(data_graph: Dict[str, Any], inputs: dict): # Generate result and thought if isinstance(langchain_object, Chain): + if inputs is None: + raise ValueError("Inputs must be provided for a Chain") logger.debug("Generating result and thought") result = get_result_and_thought(langchain_object, inputs) logger.debug("Generated result and thought")