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,
|
template: Prompt,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> Text:
|
) -> Text:
|
||||||
|
|
||||||
prompt_template = PromptTemplate.from_template(template)
|
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:
|
try:
|
||||||
formated_prompt = prompt_template.format(**kwargs)
|
formated_prompt = prompt_template.format(**kwargs)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue