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>
This commit is contained in:
Eric Hare 2024-11-12 12:55:28 -08:00 committed by GitHub
commit be44183345
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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