From e98e0b22dfb004faa6a1590251009dc90a45599b Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 29 Jun 2023 20:43:22 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(vertex/base.py):=20add=20inp?= =?UTF-8?q?ut=20types=20from=20template=5Fdicts=20to=20optional=5Finputs?= =?UTF-8?q?=20=F0=9F=90=9B=20fix(interface/initialize/loading.py):=20handl?= =?UTF-8?q?e=20BaseOutputParser=20instances=20in=20instantiate=5Fprompt=20?= =?UTF-8?q?The=20`optional=5Finputs`=20list=20in=20the=20`Vertex`=20class?= =?UTF-8?q?=20is=20now=20extended=20with=20the=20`input=5Ftypes`=20from=20?= =?UTF-8?q?the=20`template=5Fdicts`=20dictionary.=20This=20ensures=20that?= =?UTF-8?q?=20the=20`optional=5Finputs`=20list=20contains=20all=20the=20in?= =?UTF-8?q?put=20types=20that=20are=20not=20required.=20In=20the=20`instan?= =?UTF-8?q?tiate=5Fprompt`=20function,=20if=20the=20`variable`=20is=20an?= =?UTF-8?q?=20instance=20of=20`BaseOutputParser`=20and=20has=20a=20`get=5F?= =?UTF-8?q?format=5Finstructions`=20method,=20the=20`format=5Fkwargs`=20di?= =?UTF-8?q?ctionary=20is=20updated=20with=20the=20result=20of=20calling=20?= =?UTF-8?q?`get=5Fformat=5Finstructions()`.=20This=20allows=20handling=20`?= =?UTF-8?q?BaseOutputParser`=20instances=20correctly=20in=20the=20`instant?= =?UTF-8?q?iate=5Fprompt`=20function.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/graph/vertex/base.py | 8 ++++++++ src/backend/langflow/interface/initialize/loading.py | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/backend/langflow/graph/vertex/base.py b/src/backend/langflow/graph/vertex/base.py index 5e723b989..79c3270fb 100644 --- a/src/backend/langflow/graph/vertex/base.py +++ b/src/backend/langflow/graph/vertex/base.py @@ -46,6 +46,14 @@ class Vertex: for key, value in template_dicts.items() if not value["required"] ] + # Add the template_dicts[key]["input_types"] to the optional_inputs + self.optional_inputs.extend( + [ + input_type + for value in template_dicts.values() + for input_type in value.get("input_types", []) + ] + ) template_dict = self.data["node"]["template"] self.vertex_type = ( diff --git a/src/backend/langflow/interface/initialize/loading.py b/src/backend/langflow/interface/initialize/loading.py index eed253192..6267dd400 100644 --- a/src/backend/langflow/interface/initialize/loading.py +++ b/src/backend/langflow/interface/initialize/loading.py @@ -7,7 +7,8 @@ from langchain.agents.agent import AgentExecutor from langchain.agents.agent_toolkits.base import BaseToolkit from langchain.agents.tools import BaseTool from langflow.interface.initialize.vector_store import vecstore_initializer -from langchain.schema import Document + +from langchain.schema import Document, BaseOutputParser from pydantic import ValidationError from langflow.interface.custom_lists import CUSTOM_NODES @@ -130,6 +131,10 @@ def instantiate_prompt(node_type, class_object, params): variable = params[input_variable] if isinstance(variable, str): format_kwargs[input_variable] = variable + elif isinstance(variable, BaseOutputParser) and hasattr( + variable, "get_format_instructions" + ): + format_kwargs[input_variable] = variable.get_format_instructions() # check if is a list of Document elif isinstance(variable, List) and all( isinstance(item, Document) for item in variable