From 6f9520d620b62fe88ed85cfecc836616aca96a14 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 7 Jul 2023 15:54:15 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20add=20type=20hin?= =?UTF-8?q?t=20for=20'template'=20attribute=20in=20FrontendNodeRequest=20c?= =?UTF-8?q?lass=20=F0=9F=90=9B=20fix(utils.py):=20add=20input=20validation?= =?UTF-8?q?=20for=20'chat=5Finputs.message'=20to=20prevent=20errors=20when?= =?UTF-8?q?=20no=20message=20is=20provided=20=F0=9F=90=9B=20fix(loading.py?= =?UTF-8?q?):=20add=20type=20hint=20for=20'format=5Fkwargs'=20variable=20i?= =?UTF-8?q?n=20instantiate=5Fprompt=20function=20=F0=9F=90=9B=20fix(base.p?= =?UTF-8?q?y):=20add=20type=20hint=20for=20'inputs'=20parameter=20in=20get?= =?UTF-8?q?=5Fresult=5Fand=5Fsteps=20function=20The=20changes=20in=20`base?= =?UTF-8?q?.py`=20and=20`utils.py`=20are=20bug=20fixes=20that=20address=20?= =?UTF-8?q?potential=20issues=20in=20the=20code.=20The=20type=20hint=20for?= =?UTF-8?q?=20the=20'template'=20attribute=20in=20the=20`FrontendNodeReque?= =?UTF-8?q?st`=20class=20is=20added=20to=20improve=20code=20clarity=20and?= =?UTF-8?q?=20maintainability.=20The=20input=20validation=20for=20'chat=5F?= =?UTF-8?q?inputs.message'=20in=20the=20`process=5Fgraph`=20function=20ens?= =?UTF-8?q?ures=20that=20an=20error=20is=20raised=20when=20no=20message=20?= =?UTF-8?q?is=20provided,=20preventing=20potential=20issues=20down=20the?= =?UTF-8?q?=20line.=20In=20`loading.py`,=20the=20type=20hint=20for=20the?= =?UTF-8?q?=20'format=5Fkwargs'=20variable=20in=20the=20`instantiate=5Fpro?= =?UTF-8?q?mpt`=20function=20improves=20type=20safety.=20Lastly,=20in=20`b?= =?UTF-8?q?ase.py`,=20the=20type=20hint=20for=20the=20'inputs'=20parameter?= =?UTF-8?q?=20in=20the=20`get=5Fresult=5Fand=5Fsteps`=20function=20ensures?= =?UTF-8?q?=20proper=20type=20checking.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/base.py | 2 +- src/backend/langflow/chat/utils.py | 4 ++++ src/backend/langflow/interface/initialize/loading.py | 2 +- src/backend/langflow/processing/base.py | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/api/v1/base.py b/src/backend/langflow/api/v1/base.py index 28be40ae0..420e1645f 100644 --- a/src/backend/langflow/api/v1/base.py +++ b/src/backend/langflow/api/v1/base.py @@ -14,7 +14,7 @@ class Code(BaseModel): class FrontendNodeRequest(FrontendNode): - template: dict + template: dict # type: ignore class ValidatePromptRequest(BaseModel): diff --git a/src/backend/langflow/chat/utils.py b/src/backend/langflow/chat/utils.py index d070a7457..7db65b8e3 100644 --- a/src/backend/langflow/chat/utils.py +++ b/src/backend/langflow/chat/utils.py @@ -21,6 +21,10 @@ async def process_graph( # Generate result and thought try: + if not chat_inputs.message: + logger.debug("No message provided") + raise ValueError("No message provided") + logger.debug("Generating result and thought") result, intermediate_steps = await get_result_and_steps( langchain_object, chat_inputs.message, websocket=websocket diff --git a/src/backend/langflow/interface/initialize/loading.py b/src/backend/langflow/interface/initialize/loading.py index d56445f2a..37dbdcda1 100644 --- a/src/backend/langflow/interface/initialize/loading.py +++ b/src/backend/langflow/interface/initialize/loading.py @@ -193,7 +193,7 @@ def instantiate_prompt(node_type, class_object, params: Dict): prompt = class_object(**params) - format_kwargs = {} + format_kwargs: Dict[str, Any] = {} for input_variable in prompt.input_variables: if input_variable in params: variable = params[input_variable] diff --git a/src/backend/langflow/processing/base.py b/src/backend/langflow/processing/base.py index b39ad4af1..478b98816 100644 --- a/src/backend/langflow/processing/base.py +++ b/src/backend/langflow/processing/base.py @@ -1,3 +1,4 @@ +from typing import Union from langflow.api.v1.callback import ( AsyncStreamingLLMCallbackHandler, StreamingLLMCallbackHandler, @@ -6,7 +7,7 @@ from langflow.processing.process import fix_memory_inputs, format_actions from langflow.utils.logger import logger -async def get_result_and_steps(langchain_object, inputs: dict, **kwargs): +async def get_result_and_steps(langchain_object, inputs: Union[dict, str], **kwargs): """Get result and thought from extracted json""" try: