PromptComponent now handles Record inputs
This commit is contained in:
parent
1d49876647
commit
d413b2b6fc
1 changed files with 5 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from langchain_core.prompts import PromptTemplate
|
from langchain_core.prompts import PromptTemplate
|
||||||
from langflow import CustomComponent
|
from langflow import CustomComponent
|
||||||
from langflow.field_typing import Prompt, TemplateField, Text
|
from langflow.field_typing import Prompt, TemplateField, Text
|
||||||
|
from langflow.schema import Record
|
||||||
|
|
||||||
|
|
||||||
class PromptComponent(CustomComponent):
|
class PromptComponent(CustomComponent):
|
||||||
|
|
@ -20,6 +21,10 @@ class PromptComponent(CustomComponent):
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> Text:
|
) -> Text:
|
||||||
prompt_template = PromptTemplate.from_template(template)
|
prompt_template = PromptTemplate.from_template(template)
|
||||||
|
|
||||||
|
for key, value in kwargs.copy().items():
|
||||||
|
if isinstance(value, Record):
|
||||||
|
kwargs[key] = value.text
|
||||||
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