feat: Add EmbedComponent and PromptComponent to langflow components
This commit is contained in:
parent
79615816a4
commit
6cc31da766
2 changed files with 39 additions and 0 deletions
15
src/backend/base/langflow/components/experimental/Embed.py
Normal file
15
src/backend/base/langflow/components/experimental/Embed.py
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
from langflow.custom import CustomComponent
|
||||||
|
from langflow.schema import Record
|
||||||
|
from langflow.field_typing import Embeddings
|
||||||
|
|
||||||
|
|
||||||
|
class EmbedComponent(CustomComponent):
|
||||||
|
display_name = "Embed Texts"
|
||||||
|
|
||||||
|
def build_config(self):
|
||||||
|
return {"texts": {"display_name": "Texts"}, "embbedings": {"display_name": "Embeddings"}}
|
||||||
|
|
||||||
|
def build(self, texts: list[str], embbedings: Embeddings) -> Embeddings:
|
||||||
|
vectors = Record(vector=embbedings.embed_documents(texts))
|
||||||
|
self.status = vectors
|
||||||
|
return vectors
|
||||||
24
src/backend/base/langflow/components/prompts/Prompt.py
Normal file
24
src/backend/base/langflow/components/prompts/Prompt.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
from langflow.custom import CustomComponent
|
||||||
|
from langflow.field_typing import TemplateField
|
||||||
|
from langflow.field_typing.prompt import Prompt
|
||||||
|
|
||||||
|
|
||||||
|
class PromptComponent(CustomComponent):
|
||||||
|
display_name: str = "Empty Prompt"
|
||||||
|
description: str = "Create a prompt template with dynamic variables."
|
||||||
|
icon = "prompts"
|
||||||
|
|
||||||
|
def build_config(self):
|
||||||
|
return {
|
||||||
|
"template": TemplateField(display_name="Template"),
|
||||||
|
"code": TemplateField(advanced=True),
|
||||||
|
}
|
||||||
|
|
||||||
|
async def build(
|
||||||
|
self,
|
||||||
|
template: Prompt,
|
||||||
|
**kwargs,
|
||||||
|
) -> Prompt:
|
||||||
|
prompt = await Prompt.from_template_and_variables(template, kwargs)
|
||||||
|
self.status = prompt.format_text()
|
||||||
|
return prompt
|
||||||
Loading…
Add table
Add a link
Reference in a new issue