From 0820a46c54bc227c666d51fd08b4015363cf20ea Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 21 Feb 2024 16:03:45 -0300 Subject: [PATCH] Refactor PromptComponent to extract attributes from kwargs --- src/backend/langflow/components/prompts/Prompt.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/langflow/components/prompts/Prompt.py b/src/backend/langflow/components/prompts/Prompt.py index 2ca7eb71c..934cfddf5 100644 --- a/src/backend/langflow/components/prompts/Prompt.py +++ b/src/backend/langflow/components/prompts/Prompt.py @@ -19,8 +19,15 @@ class PromptComponent(CustomComponent): template: Prompt, **kwargs, ) -> Text: + prompt_template = PromptTemplate.from_template(template) + attributes_to_check = ["text", "page_content"] + for key, value in kwargs.items(): + for attribute in attributes_to_check: + if hasattr(value, attribute): + kwargs[key] = getattr(value, attribute) + try: formated_prompt = prompt_template.format(**kwargs) except Exception as exc: