Refactor PromptComponent to extract attributes from kwargs
This commit is contained in:
parent
7fcf3a4cc2
commit
0820a46c54
1 changed files with 7 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue