From be44183345ca9e76228c8da54c58db7c809fb72b Mon Sep 17 00:00:00 2001 From: Eric Hare Date: Tue, 12 Nov 2024 12:55:28 -0800 Subject: [PATCH] fix: KeyError in Langchain Hub component (#4530) * fix: KeyError in Langchain Hub component * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- .../langflow/components/langchain_utilities/langchain_hub.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/components/langchain_utilities/langchain_hub.py b/src/backend/base/langflow/components/langchain_utilities/langchain_hub.py index d9df71972..623d0f19c 100644 --- a/src/backend/base/langflow/components/langchain_utilities/langchain_hub.py +++ b/src/backend/base/langflow/components/langchain_utilities/langchain_hub.py @@ -99,9 +99,11 @@ class LangChainHubPromptComponent(Component): template = self._fetch_langchain_hub_template() # Get the parameters from the attributes - original_params = {k.removeprefix("param_"): v for k, v in self._attributes.items()} + params_dict = {param: getattr(self, "param_" + param, f"{{{param}}}") for param in template.input_variables} + original_params = {k: v.text if hasattr(v, "text") else v for k, v in params_dict.items() if v is not None} prompt_value = template.invoke(original_params) + # Update the template with the new value original_params["template"] = prompt_value.to_string() # Now pass the filtered attributes to the function