🐛 fix(vertex/base.py): add input types from template_dicts to optional_inputs

🐛 fix(interface/initialize/loading.py): handle BaseOutputParser instances in instantiate_prompt
The `optional_inputs` list in the `Vertex` class is now extended with the `input_types` from the `template_dicts` dictionary. This ensures that the `optional_inputs` list contains all the input types that are not required. In the `instantiate_prompt` function, if the `variable` is an instance of `BaseOutputParser` and has a `get_format_instructions` method, the `format_kwargs` dictionary is updated with the result of calling `get_format_instructions()`. This allows handling `BaseOutputParser` instances correctly in the `instantiate_prompt` function.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-29 20:43:22 -03:00
commit e98e0b22df
2 changed files with 14 additions and 1 deletions

View file

@ -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 = (

View file

@ -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