custom prompt experiment

This commit is contained in:
Gabriel Almeida 2023-04-01 18:41:27 -03:00
commit 12c21b0185
7 changed files with 28 additions and 55 deletions

View file

@ -1,7 +1,9 @@
from langflow.template import nodes
CUSTOM_NODES = {
"prompts": {**nodes.ZeroShotPromptNode().to_dict()},
"prompts": {
**nodes.ZeroShotPromptNode().to_dict(),
},
"tools": {**nodes.PythonFunctionNode().to_dict(), **nodes.ToolNode().to_dict()},
"agents": {
**nodes.JsonAgentNode().to_dict(),

View file

@ -3,6 +3,7 @@ from typing import Any, Dict, Optional, Union
from pydantic import BaseModel
from langflow.template.constants import FORCE_SHOW_FIELDS
from langflow.utils import constants
@ -68,17 +69,7 @@ class TemplateFieldCreator(BaseModel, ABC):
# Show or not field
self.show = bool(
(self.required and key not in ["input_variables"])
or key
in [
"allowed_tools",
"memory",
"prefix",
"examples",
"temperature",
"model_name",
"headers",
"max_value_length",
]
or key in FORCE_SHOW_FIELDS
or "api_key" in key
)

View file

@ -49,6 +49,16 @@ class ZeroShotPromptNode(FrontendNode):
return super().to_dict()
class PromptTemplateNode(FrontendNode):
name: str = "PromptTemplate"
template: Template
description: str
base_classes: list[str] = ["BasePromptTemplate"]
def to_dict(self):
return super().to_dict()
class PythonFunctionNode(FrontendNode):
name: str = "PythonFunction"
template: Template = Template(

View file

@ -3,6 +3,7 @@ import inspect
import re
from typing import Dict, Optional
from langflow.template.constants import FORCE_SHOW_FIELDS
from langflow.utils import constants
@ -284,17 +285,7 @@ def format_dict(d, name: Optional[str] = None):
# Show or not field
value["show"] = bool(
(value["required"] and key not in ["input_variables"])
or key
in [
"allowed_tools",
"memory",
"prefix",
"examples",
"temperature",
"model_name",
"headers",
"max_value_length",
]
or key in FORCE_SHOW_FIELDS
or "api_key" in key
)