Refactor PromptComponent to extract attributes from kwargs

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-21 16:03:45 -03:00
commit 0820a46c54

View file

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