feat: implement node templates
This commit is contained in:
parent
405041f9c8
commit
d93ecee876
4 changed files with 92 additions and 38 deletions
|
|
@ -1,42 +1,6 @@
|
||||||
from langchain.agents.mrkl import prompt
|
from langflow.node.nodes import ZeroShotPromptNode
|
||||||
|
|
||||||
|
|
||||||
def get_custom_prompts():
|
def get_custom_prompts():
|
||||||
"""Get custom prompts."""
|
"""Get custom prompts."""
|
||||||
|
return ZeroShotPromptNode().to_dict()
|
||||||
return {
|
|
||||||
"ZeroShotPrompt": {
|
|
||||||
"template": {
|
|
||||||
"_type": "zero_shot",
|
|
||||||
"prefix": {
|
|
||||||
"type": "str",
|
|
||||||
"required": False,
|
|
||||||
"placeholder": "",
|
|
||||||
"list": False,
|
|
||||||
"show": True,
|
|
||||||
"multiline": True,
|
|
||||||
"value": prompt.PREFIX,
|
|
||||||
},
|
|
||||||
"suffix": {
|
|
||||||
"type": "str",
|
|
||||||
"required": True,
|
|
||||||
"placeholder": "",
|
|
||||||
"list": False,
|
|
||||||
"show": True,
|
|
||||||
"multiline": True,
|
|
||||||
"value": prompt.SUFFIX,
|
|
||||||
},
|
|
||||||
"format_instructions": {
|
|
||||||
"type": "str",
|
|
||||||
"required": False,
|
|
||||||
"placeholder": "",
|
|
||||||
"list": False,
|
|
||||||
"show": True,
|
|
||||||
"multiline": True,
|
|
||||||
"value": prompt.FORMAT_INSTRUCTIONS,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"description": "Prompt template for Zero Shot Agent.",
|
|
||||||
"base_classes": ["BasePromptTemplate"],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
0
src/backend/langflow/node/__init__.py
Normal file
0
src/backend/langflow/node/__init__.py
Normal file
46
src/backend/langflow/node/nodes.py
Normal file
46
src/backend/langflow/node/nodes.py
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
from langflow.node.template import Field, FrontendNode, Template
|
||||||
|
from langchain.agents.mrkl import prompt
|
||||||
|
|
||||||
|
|
||||||
|
class ZeroShotPromptNode(FrontendNode):
|
||||||
|
_name = "ZeroShotPrompt"
|
||||||
|
template = Template(
|
||||||
|
type_name="zero_shot",
|
||||||
|
fields=[
|
||||||
|
Field(
|
||||||
|
field_type="str",
|
||||||
|
required=False,
|
||||||
|
placeholder="",
|
||||||
|
is_list=False,
|
||||||
|
show=True,
|
||||||
|
multiline=True,
|
||||||
|
value=prompt.PREFIX,
|
||||||
|
name="prefix",
|
||||||
|
),
|
||||||
|
Field(
|
||||||
|
field_type="str",
|
||||||
|
required=True,
|
||||||
|
placeholder="",
|
||||||
|
is_list=False,
|
||||||
|
show=True,
|
||||||
|
multiline=True,
|
||||||
|
value=prompt.SUFFIX,
|
||||||
|
name="suffix",
|
||||||
|
),
|
||||||
|
Field(
|
||||||
|
field_type="str",
|
||||||
|
required=False,
|
||||||
|
placeholder="",
|
||||||
|
is_list=False,
|
||||||
|
show=True,
|
||||||
|
multiline=True,
|
||||||
|
value=prompt.FORMAT_INSTRUCTIONS,
|
||||||
|
name="format_instructions",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
description = "Prompt template for Zero Shot Agent."
|
||||||
|
base_classes = ["BasePromptTemplate"]
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return super().to_dict()
|
||||||
44
src/backend/langflow/node/template.py
Normal file
44
src/backend/langflow/node/template.py
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
from typing import Any
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class Field(BaseModel):
|
||||||
|
field_type: str = "str"
|
||||||
|
required: bool = False
|
||||||
|
placeholder: str = ""
|
||||||
|
is_list: bool = False
|
||||||
|
show: bool = True
|
||||||
|
multiline: bool = False
|
||||||
|
value: Any = None
|
||||||
|
# _name will be used to store the name of the field
|
||||||
|
# in the template
|
||||||
|
name: str = None
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return self.dict()
|
||||||
|
|
||||||
|
|
||||||
|
class Template(BaseModel):
|
||||||
|
type_name: str
|
||||||
|
fields: list[Field]
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
result = {field.name: field.to_dict() for field in self.fields}
|
||||||
|
result["_type"] = self.type_name
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class FrontendNode(BaseModel):
|
||||||
|
template: Template
|
||||||
|
description: str
|
||||||
|
base_classes: list
|
||||||
|
_name: str = None
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
return {
|
||||||
|
self._name: {
|
||||||
|
"template": self.template.to_dict(),
|
||||||
|
"description": self.description,
|
||||||
|
"base_classes": self.base_classes,
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue