Refactor PromptComponent and add import statement for PromptComponent
This commit is contained in:
parent
0e5e259bae
commit
bb6a2ceb58
2 changed files with 7 additions and 3 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
from langchain_core.prompts import PromptTemplate
|
from langchain_core.prompts import PromptTemplate
|
||||||
|
|
||||||
from langflow import CustomComponent
|
from langflow import CustomComponent
|
||||||
from langflow.base.prompts.utils import dict_values_to_string
|
|
||||||
from langflow.field_typing import Prompt, TemplateField, Text
|
from langflow.field_typing import Prompt, TemplateField, Text
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -21,9 +20,13 @@ class PromptComponent(CustomComponent):
|
||||||
template: Prompt,
|
template: Prompt,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> Text:
|
) -> Text:
|
||||||
|
from langflow.base.prompts.utils import dict_values_to_string
|
||||||
|
|
||||||
prompt_template = PromptTemplate.from_template(Text(template))
|
prompt_template = PromptTemplate.from_template(Text(template))
|
||||||
kwargs = dict_values_to_string(kwargs)
|
kwargs = dict_values_to_string(kwargs)
|
||||||
kwargs = {k: "\n".join(v) if isinstance(v, list) else v for k, v in kwargs.items()}
|
kwargs = {
|
||||||
|
k: "\n".join(v) if isinstance(v, list) else v for k, v in kwargs.items()
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
formated_prompt = prompt_template.format(**kwargs)
|
formated_prompt = prompt_template.format(**kwargs)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from .ChatInput import ChatInput
|
from .ChatInput import ChatInput
|
||||||
|
from .Prompt import PromptComponent
|
||||||
from .TextInput import TextInput
|
from .TextInput import TextInput
|
||||||
|
|
||||||
__all__ = ["ChatInput", "TextInput"]
|
__all__ = ["ChatInput", "TextInput", "PromptComponent"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue