Merge remote-tracking branch 'origin/dev' into bug/component_share

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-12-10 11:58:13 -03:00
commit cdbf7b05eb
15 changed files with 164 additions and 148 deletions

View file

@ -129,7 +129,7 @@ def add_new_custom_field(
display_name=display_name, display_name=display_name,
**field_config, **field_config,
) )
template.get("template")[field_name] = new_field.to_dict() template.get("template")[field_name] = new_field.model_dump(by_alias=True, exclude_none=True)
template.get("custom_fields")[field_name] = None template.get("custom_fields")[field_name] = None
return template return template

View file

@ -1,11 +1,11 @@
from abc import ABC from typing import Any, Optional
from typing import Any, Optional, Union
from pydantic import BaseModel from pydantic import BaseModel, ConfigDict, Field, field_serializer
class TemplateFieldCreator(BaseModel, ABC): class TemplateField(BaseModel):
field_type: str = "str" model_config = ConfigDict()
field_type: str = Field(default="str", serialization_alias="type")
"""The type of field this is. Default is a string.""" """The type of field this is. Default is a string."""
required: bool = False required: bool = False
@ -14,7 +14,7 @@ class TemplateFieldCreator(BaseModel, ABC):
placeholder: str = "" placeholder: str = ""
"""A placeholder string for the field. Default is an empty string.""" """A placeholder string for the field. Default is an empty string."""
is_list: bool = False is_list: bool = Field(default=False, serialization_alias="list")
"""Defines if the field is a list. Default is False.""" """Defines if the field is a list. Default is False."""
show: bool = True show: bool = True
@ -23,19 +23,19 @@ class TemplateFieldCreator(BaseModel, ABC):
multiline: bool = False multiline: bool = False
"""Defines if the field will allow the user to open a text editor. Default is False.""" """Defines if the field will allow the user to open a text editor. Default is False."""
value: Any = None value: Any = ""
"""The value of the field. Default is None.""" """The value of the field. Default is None."""
file_types: list[str] = [] file_types: list[str] = Field(default=[], serialization_alias="fileTypes")
"""List of file types associated with the field. Default is an empty list. (duplicate)""" """List of file types associated with the field. Default is an empty list. (duplicate)"""
file_path: Union[str, None] = None file_path: Optional[str] = ""
"""The file path of the field if it is a file. Defaults to None.""" """The file path of the field if it is a file. Defaults to None."""
password: bool = False password: bool = False
"""Specifies if the field is a password. Defaults to False.""" """Specifies if the field is a password. Defaults to False."""
options: list[str] = [] options: Optional[list[str]] = None
"""List of options for the field. Only used when is_list=True. Default is an empty list.""" """List of options for the field. Only used when is_list=True. Default is an empty list."""
name: str = "" name: str = ""
@ -47,7 +47,7 @@ class TemplateFieldCreator(BaseModel, ABC):
advanced: bool = False advanced: bool = False
"""Specifies if the field will an advanced parameter (hidden). Defaults to False.""" """Specifies if the field will an advanced parameter (hidden). Defaults to False."""
input_types: list[str] = [] input_types: Optional[list[str]] = None
"""List of input types for the handle when the field has more than one type. Default is an empty list.""" """List of input types for the handle when the field has more than one type. Default is an empty list."""
dynamic: bool = False dynamic: bool = False
@ -60,21 +60,10 @@ class TemplateFieldCreator(BaseModel, ABC):
"""Specifies if the field should be refreshed. Defaults to False.""" """Specifies if the field should be refreshed. Defaults to False."""
def to_dict(self): def to_dict(self):
result = self.model_dump() return self.model_dump(by_alias=True, exclude_none=True)
# Remove key if it is None
for key in list(result.keys()):
if result[key] is None or result[key] == [] and key != "value":
del result[key]
result["type"] = result.pop("field_type")
result["list"] = result.pop("is_list")
if result.get("file_types"):
result["fileTypes"] = result.pop("file_types")
@field_serializer("file_path")
def serialize_file_path(self, value):
if self.field_type == "file": if self.field_type == "file":
result["file_path"] = self.file_path return value
return result return ""
class TemplateField(TemplateFieldCreator):
pass

View file

@ -1,7 +1,6 @@
from typing import Optional from typing import Optional
from langchain.agents import types from langchain.agents import types
from langflow.template.field.base import TemplateField from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.base import FrontendNode from langflow.template.frontend_node.base import FrontendNode
from langflow.template.template.base import Template from langflow.template.template.base import Template
@ -29,17 +28,17 @@ class SQLAgentNode(FrontendNode):
type_name="sql_agent", type_name="sql_agent",
fields=[ fields=[
TemplateField( TemplateField(
field_type="str", field_type="str", # pyright: ignore
required=True, required=True,
placeholder="", placeholder="",
is_list=False, is_list=False, # pyright: ignore
show=True, show=True,
multiline=False, multiline=False,
value="", value="",
name="database_uri", name="database_uri",
), ),
TemplateField( TemplateField(
field_type="BaseLanguageModel", field_type="BaseLanguageModel", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="llm", name="llm",
@ -50,9 +49,6 @@ class SQLAgentNode(FrontendNode):
description: str = """Construct an SQL agent from an LLM and tools.""" description: str = """Construct an SQL agent from an LLM and tools."""
base_classes: list[str] = ["AgentExecutor"] base_classes: list[str] = ["AgentExecutor"]
def to_dict(self):
return super().to_dict()
class VectorStoreRouterAgentNode(FrontendNode): class VectorStoreRouterAgentNode(FrontendNode):
name: str = "VectorStoreRouterAgent" name: str = "VectorStoreRouterAgent"
@ -60,14 +56,14 @@ class VectorStoreRouterAgentNode(FrontendNode):
type_name="vectorstorerouter_agent", type_name="vectorstorerouter_agent",
fields=[ fields=[
TemplateField( TemplateField(
field_type="VectorStoreRouterToolkit", field_type="VectorStoreRouterToolkit", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="vectorstoreroutertoolkit", name="vectorstoreroutertoolkit",
display_name="Vector Store Router Toolkit", display_name="Vector Store Router Toolkit",
), ),
TemplateField( TemplateField(
field_type="BaseLanguageModel", field_type="BaseLanguageModel", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="llm", name="llm",
@ -78,9 +74,6 @@ class VectorStoreRouterAgentNode(FrontendNode):
description: str = """Construct an agent from a Vector Store Router.""" description: str = """Construct an agent from a Vector Store Router."""
base_classes: list[str] = ["AgentExecutor"] base_classes: list[str] = ["AgentExecutor"]
def to_dict(self):
return super().to_dict()
class VectorStoreAgentNode(FrontendNode): class VectorStoreAgentNode(FrontendNode):
name: str = "VectorStoreAgent" name: str = "VectorStoreAgent"
@ -88,14 +81,14 @@ class VectorStoreAgentNode(FrontendNode):
type_name="vectorstore_agent", type_name="vectorstore_agent",
fields=[ fields=[
TemplateField( TemplateField(
field_type="VectorStoreInfo", field_type="VectorStoreInfo", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="vectorstoreinfo", name="vectorstoreinfo",
display_name="Vector Store Info", display_name="Vector Store Info",
), ),
TemplateField( TemplateField(
field_type="BaseLanguageModel", field_type="BaseLanguageModel", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="llm", name="llm",
@ -106,9 +99,6 @@ class VectorStoreAgentNode(FrontendNode):
description: str = """Construct an agent from a Vector Store.""" description: str = """Construct an agent from a Vector Store."""
base_classes: list[str] = ["AgentExecutor"] base_classes: list[str] = ["AgentExecutor"]
def to_dict(self):
return super().to_dict()
class SQLDatabaseNode(FrontendNode): class SQLDatabaseNode(FrontendNode):
name: str = "SQLDatabase" name: str = "SQLDatabase"
@ -116,9 +106,9 @@ class SQLDatabaseNode(FrontendNode):
type_name="sql_database", type_name="sql_database",
fields=[ fields=[
TemplateField( TemplateField(
field_type="str", field_type="str", # pyright: ignore
required=True, required=True,
is_list=False, is_list=False, # pyright: ignore
show=True, show=True,
multiline=False, multiline=False,
value="", value="",
@ -129,9 +119,6 @@ class SQLDatabaseNode(FrontendNode):
description: str = """SQLAlchemy wrapper around a database.""" description: str = """SQLAlchemy wrapper around a database."""
base_classes: list[str] = ["SQLDatabase"] base_classes: list[str] = ["SQLDatabase"]
def to_dict(self):
return super().to_dict()
class CSVAgentNode(FrontendNode): class CSVAgentNode(FrontendNode):
name: str = "CSVAgent" name: str = "CSVAgent"
@ -139,15 +126,15 @@ class CSVAgentNode(FrontendNode):
type_name="csv_agent", type_name="csv_agent",
fields=[ fields=[
TemplateField( TemplateField(
field_type="file", field_type="file", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="path", name="path",
value="", value="",
file_types=[".csv"], file_types=[".csv"], # pyright: ignore
), ),
TemplateField( TemplateField(
field_type="BaseLanguageModel", field_type="BaseLanguageModel", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="llm", name="llm",
@ -158,9 +145,6 @@ class CSVAgentNode(FrontendNode):
description: str = """Construct a CSV agent from a CSV and tools.""" description: str = """Construct a CSV agent from a CSV and tools."""
base_classes: list[str] = ["AgentExecutor"] base_classes: list[str] = ["AgentExecutor"]
def to_dict(self):
return super().to_dict()
class InitializeAgentNode(FrontendNode): class InitializeAgentNode(FrontendNode):
name: str = "AgentInitializer" name: str = "AgentInitializer"
@ -169,9 +153,9 @@ class InitializeAgentNode(FrontendNode):
type_name="initialize_agent", type_name="initialize_agent",
fields=[ fields=[
TemplateField( TemplateField(
field_type="str", field_type="str", # pyright: ignore
required=True, required=True,
is_list=True, is_list=True, # pyright: ignore
show=True, show=True,
multiline=False, multiline=False,
options=list(NON_CHAT_AGENTS.keys()), options=list(NON_CHAT_AGENTS.keys()),
@ -180,22 +164,22 @@ class InitializeAgentNode(FrontendNode):
advanced=False, advanced=False,
), ),
TemplateField( TemplateField(
field_type="BaseChatMemory", field_type="BaseChatMemory", # pyright: ignore
required=False, required=False,
show=True, show=True,
name="memory", name="memory",
advanced=False, advanced=False,
), ),
TemplateField( TemplateField(
field_type="Tool", field_type="Tool", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="tools", name="tools",
is_list=True, is_list=True, # pyright: ignore
advanced=False, advanced=False,
), ),
TemplateField( TemplateField(
field_type="BaseLanguageModel", field_type="BaseLanguageModel", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="llm", name="llm",
@ -207,9 +191,6 @@ class InitializeAgentNode(FrontendNode):
description: str = """Construct a zero shot agent from an LLM and tools.""" description: str = """Construct a zero shot agent from an LLM and tools."""
base_classes: list[str] = ["AgentExecutor", "Callable"] base_classes: list[str] = ["AgentExecutor", "Callable"]
def to_dict(self):
return super().to_dict()
@staticmethod @staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None: def format_field(field: TemplateField, name: Optional[str] = None) -> None:
# do nothing and don't return anything # do nothing and don't return anything
@ -222,13 +203,13 @@ class JsonAgentNode(FrontendNode):
type_name="json_agent", type_name="json_agent",
fields=[ fields=[
TemplateField( TemplateField(
field_type="BaseToolkit", field_type="BaseToolkit", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="toolkit", name="toolkit",
), ),
TemplateField( TemplateField(
field_type="BaseLanguageModel", field_type="BaseLanguageModel", # pyright: ignore
required=True, required=True,
show=True, show=True,
name="llm", name="llm",
@ -238,6 +219,3 @@ class JsonAgentNode(FrontendNode):
) )
description: str = """Construct a json agent from an LLM and tools.""" description: str = """Construct a json agent from an LLM and tools."""
base_classes: list[str] = ["AgentExecutor"] base_classes: list[str] = ["AgentExecutor"]
def to_dict(self):
return super().to_dict()

View file

@ -7,7 +7,7 @@ from langflow.template.frontend_node.constants import CLASSES_TO_REMOVE, FORCE_S
from langflow.template.frontend_node.formatter import field_formatters from langflow.template.frontend_node.formatter import field_formatters
from langflow.template.template.base import Template from langflow.template.template.base import Template
from langflow.utils import constants from langflow.utils import constants
from pydantic import BaseModel, Field from pydantic import BaseModel, Field, field_serializer, model_serializer
class FieldFormatters(BaseModel): class FieldFormatters(BaseModel):
@ -63,26 +63,32 @@ class FrontendNode(BaseModel):
"""Sets the documentation of the frontend node.""" """Sets the documentation of the frontend node."""
self.documentation = documentation self.documentation = documentation
def process_base_classes(self) -> None: @field_serializer("base_classes")
def process_base_classes(self, base_classes: List[str]) -> List[str]:
"""Removes unwanted base classes from the list of base classes.""" """Removes unwanted base classes from the list of base classes."""
self.base_classes = [base_class for base_class in self.base_classes if base_class not in CLASSES_TO_REMOVE]
return [base_class for base_class in base_classes if base_class not in CLASSES_TO_REMOVE]
@field_serializer("display_name")
def process_display_name(self, display_name: str) -> str:
"""Sets the display name of the frontend node."""
return display_name or self.name
@model_serializer(mode="wrap")
def serialize(self, handler):
result = handler(self)
if hasattr(self, "template") and hasattr(self.template, "to_dict"):
result["template"] = self.template.to_dict(self.format_field)
name = result.pop("name")
return {name: result}
# For backwards compatibility
def to_dict(self) -> dict: def to_dict(self) -> dict:
"""Returns a dict representation of the frontend node.""" """Returns a dict representation of the frontend node."""
self.process_base_classes()
return { return self.model_dump(by_alias=True, exclude_none=True)
self.name: {
"template": self.template.to_dict(self.format_field),
"description": self.description,
"base_classes": self.base_classes,
"display_name": self.display_name or self.name,
"custom_fields": self.custom_fields,
"output_types": self.output_types,
"documentation": self.documentation,
"beta": self.beta,
"error": self.error,
},
}
def add_extra_fields(self) -> None: def add_extra_fields(self) -> None:
pass pass

View file

@ -247,9 +247,6 @@ class CombineDocsChainNode(FrontendNode):
description: str = """Load question answering chain.""" description: str = """Load question answering chain."""
base_classes: list[str] = ["BaseCombineDocumentsChain", "Callable"] base_classes: list[str] = ["BaseCombineDocumentsChain", "Callable"]
def to_dict(self):
return super().to_dict()
@staticmethod @staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None: def format_field(field: TemplateField, name: Optional[str] = None) -> None:
# do nothing and don't return anything # do nothing and don't return anything

View file

@ -1,5 +1,7 @@
from typing import Optional from typing import Optional
from pydantic import field_serializer
from langflow.template.field.base import TemplateField from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.base import FrontendNode from langflow.template.frontend_node.base import FrontendNode
from langflow.template.template.base import Template from langflow.template.template.base import Template
@ -67,19 +69,8 @@ class CustomComponentFrontendNode(FrontendNode):
description: Optional[str] = None description: Optional[str] = None
base_classes: list[str] = [] base_classes: list[str] = []
def to_dict(self) -> dict: @field_serializer("display_name")
"""Returns a dict representation of the frontend node.""" def process_display_name(self, display_name: str) -> str:
self.process_base_classes() """Sets the display name of the frontend node."""
return {
self.name: { return display_name
"template": self.template.to_dict(self.format_field),
"description": self.description,
"base_classes": self.base_classes,
"display_name": self.display_name,
"custom_fields": self.custom_fields,
"output_types": self.output_types,
"documentation": self.documentation,
"beta": self.beta,
"error": self.error,
},
}

View file

@ -129,7 +129,7 @@ class MultilineFieldFormatter(FieldFormatter):
class DefaultValueFormatter(FieldFormatter): class DefaultValueFormatter(FieldFormatter):
def format(self, field: TemplateField, name: Optional[str] = None) -> None: def format(self, field: TemplateField, name: Optional[str] = None) -> None:
value = field.to_dict() value = field.model_dump(by_alias=True, exclude_none=True)
if "default" in value: if "default" in value:
field.value = value["default"] field.value = value["default"]
@ -144,7 +144,7 @@ class HeadersDefaultValueFormatter(FieldFormatter):
class DictCodeFileFormatter(FieldFormatter): class DictCodeFileFormatter(FieldFormatter):
def format(self, field: TemplateField, name: Optional[str] = None) -> None: def format(self, field: TemplateField, name: Optional[str] = None) -> None:
key = field.name key = field.name
value = field.to_dict() value = field.model_dump(by_alias=True, exclude_none=True)
_type = value["type"] _type = value["type"]
if "dict" in _type.lower() and key == "dict_": if "dict" in _type.lower() and key == "dict_":
field.field_type = "file" field.field_type = "file"

View file

@ -1,14 +1,9 @@
from typing import Optional from typing import Optional
from langchain.agents.mrkl import prompt from langchain.agents.mrkl import prompt
from langflow.template.frontend_node.constants import (
DEFAULT_PROMPT,
HUMAN_PROMPT,
SYSTEM_PROMPT,
)
from langflow.template.field.base import TemplateField from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.base import FrontendNode from langflow.template.frontend_node.base import FrontendNode
from langflow.template.frontend_node.constants import DEFAULT_PROMPT, HUMAN_PROMPT, SYSTEM_PROMPT
from langflow.template.template.base import Template from langflow.template.template.base import Template
@ -50,9 +45,6 @@ class PromptTemplateNode(FrontendNode):
description: str description: str
base_classes: list[str] = ["BasePromptTemplate"] base_classes: list[str] = ["BasePromptTemplate"]
def to_dict(self):
return super().to_dict()
@staticmethod @staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None: def format_field(field: TemplateField, name: Optional[str] = None) -> None:
FrontendNode.format_field(field, name) FrontendNode.format_field(field, name)
@ -66,9 +58,6 @@ class BasePromptFrontendNode(FrontendNode):
description: str description: str
base_classes: list[str] base_classes: list[str]
def to_dict(self):
return super().to_dict()
class ZeroShotPromptNode(BasePromptFrontendNode): class ZeroShotPromptNode(BasePromptFrontendNode):
name: str = "ZeroShotPrompt" name: str = "ZeroShotPrompt"
@ -110,9 +99,6 @@ class ZeroShotPromptNode(BasePromptFrontendNode):
description: str = "Prompt template for Zero Shot Agent." description: str = "Prompt template for Zero Shot Agent."
base_classes: list[str] = ["BasePromptTemplate"] base_classes: list[str] = ["BasePromptTemplate"]
def to_dict(self):
return super().to_dict()
@staticmethod @staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None: def format_field(field: TemplateField, name: Optional[str] = None) -> None:
PromptFrontendNode.format_field(field, name) PromptFrontendNode.format_field(field, name)

View file

@ -1,9 +1,7 @@
from langflow.template.field.base import TemplateField from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.base import FrontendNode from langflow.template.frontend_node.base import FrontendNode
from langflow.template.template.base import Template from langflow.template.template.base import Template
from langflow.utils.constants import ( from langflow.utils.constants import DEFAULT_PYTHON_FUNCTION
DEFAULT_PYTHON_FUNCTION,
)
class ToolNode(FrontendNode): class ToolNode(FrontendNode):
@ -57,9 +55,6 @@ class ToolNode(FrontendNode):
description: str = "Converts a chain, agent or function into a tool." description: str = "Converts a chain, agent or function into a tool."
base_classes: list[str] = ["Tool", "BaseTool"] base_classes: list[str] = ["Tool", "BaseTool"]
def to_dict(self):
return super().to_dict()
class PythonFunctionToolNode(FrontendNode): class PythonFunctionToolNode(FrontendNode):
name: str = "PythonFunctionTool" name: str = "PythonFunctionTool"
@ -113,9 +108,6 @@ class PythonFunctionToolNode(FrontendNode):
description: str = "Python function to be executed." description: str = "Python function to be executed."
base_classes: list[str] = ["BaseTool", "Tool"] base_classes: list[str] = ["BaseTool", "Tool"]
def to_dict(self):
return super().to_dict()
class PythonFunctionNode(FrontendNode): class PythonFunctionNode(FrontendNode):
name: str = "PythonFunction" name: str = "PythonFunction"
@ -136,6 +128,3 @@ class PythonFunctionNode(FrontendNode):
) )
description: str = "Python function to be executed." description: str = "Python function to be executed."
base_classes: list[str] = ["Callable"] base_classes: list[str] = ["Callable"]
def to_dict(self):
return super().to_dict()

View file

@ -1,9 +1,8 @@
from typing import Callable, Optional, Union from typing import Callable, Union
from pydantic import BaseModel
from langflow.template.field.base import TemplateField from langflow.template.field.base import TemplateField
from langflow.utils.constants import DIRECT_TYPES from langflow.utils.constants import DIRECT_TYPES
from pydantic import BaseModel, model_serializer
class Template(BaseModel): class Template(BaseModel):
@ -12,12 +11,11 @@ class Template(BaseModel):
def process_fields( def process_fields(
self, self,
name: Optional[str] = None,
format_field_func: Union[Callable, None] = None, format_field_func: Union[Callable, None] = None,
): ):
if format_field_func: if format_field_func:
for field in self.fields: for field in self.fields:
format_field_func(field, name) format_field_func(field, self.type_name)
def sort_fields(self): def sort_fields(self):
# first sort alphabetically # first sort alphabetically
@ -25,12 +23,19 @@ class Template(BaseModel):
self.fields.sort(key=lambda x: x.name) self.fields.sort(key=lambda x: x.name)
self.fields.sort(key=lambda x: x.field_type in DIRECT_TYPES, reverse=False) self.fields.sort(key=lambda x: x.field_type in DIRECT_TYPES, reverse=False)
def to_dict(self, format_field_func=None): @model_serializer(mode="wrap")
self.process_fields(self.type_name, format_field_func) def serialize_model(self, handler):
self.sort_fields() result = handler(self)
result = {field.name: field.to_dict() for field in self.fields} for field in self.fields:
result["_type"] = self.type_name # type: ignore result[field.name] = field.model_dump(by_alias=True, exclude_none=True)
result["_type"] = result.pop("type_name")
return result return result
# For backwards compatibility
def to_dict(self, format_field_func=None):
self.process_fields(format_field_func)
self.sort_fields()
return self.model_dump(by_alias=True, exclude_none=True, exclude={"fields"})
def add_field(self, field: TemplateField) -> None: def add_field(self, field: TemplateField) -> None:
self.fields.append(field) self.fields.append(field)

View file

@ -28,6 +28,7 @@ def test_zero_shot_agent(client: TestClient, logged_in_headers):
"list": True, "list": True,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
# Additional assertions for other template variables # Additional assertions for other template variables
@ -43,6 +44,7 @@ def test_zero_shot_agent(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["llm"] == { assert template["llm"] == {
"required": True, "required": True,
@ -56,6 +58,7 @@ def test_zero_shot_agent(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["output_parser"] == { assert template["output_parser"] == {
"required": False, "required": False,
@ -69,6 +72,7 @@ def test_zero_shot_agent(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["input_variables"] == { assert template["input_variables"] == {
"required": False, "required": False,
@ -82,6 +86,7 @@ def test_zero_shot_agent(client: TestClient, logged_in_headers):
"list": True, "list": True,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["prefix"] == { assert template["prefix"] == {
"required": False, "required": False,
@ -96,6 +101,7 @@ def test_zero_shot_agent(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["suffix"] == { assert template["suffix"] == {
"required": False, "required": False,
@ -110,6 +116,7 @@ def test_zero_shot_agent(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
@ -135,6 +142,9 @@ def test_json_agent(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"file_path": "",
"fileTypes": [],
"value": "",
} }
assert template["llm"] == { assert template["llm"] == {
"required": True, "required": True,
@ -149,6 +159,9 @@ def test_json_agent(client: TestClient, logged_in_headers):
"advanced": False, "advanced": False,
"display_name": "LLM", "display_name": "LLM",
"info": "", "info": "",
"file_path": "",
"fileTypes": [],
"value": "",
} }
@ -174,7 +187,7 @@ def test_csv_agent(client: TestClient, logged_in_headers):
"name": "path", "name": "path",
"type": "file", "type": "file",
"list": False, "list": False,
"file_path": None, "file_path": "",
"advanced": False, "advanced": False,
"info": "", "info": "",
} }
@ -191,4 +204,7 @@ def test_csv_agent(client: TestClient, logged_in_headers):
"advanced": False, "advanced": False,
"display_name": "LLM", "display_name": "LLM",
"info": "", "info": "",
"file_path": "",
"fileTypes": [],
"value": "",
} }

View file

@ -35,6 +35,7 @@ def test_llm_checker_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["_type"] == "LLMCheckerChain" assert template["_type"] == "LLMCheckerChain"
@ -69,6 +70,7 @@ def test_llm_math_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["verbose"] == { assert template["verbose"] == {
"required": False, "required": False,
@ -83,6 +85,7 @@ def test_llm_math_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": True, "advanced": True,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["llm"] == { assert template["llm"] == {
"required": True, "required": True,
@ -96,6 +99,7 @@ def test_llm_math_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["input_key"] == { assert template["input_key"] == {
"required": True, "required": True,
@ -110,6 +114,7 @@ def test_llm_math_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": True, "advanced": True,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["output_key"] == { assert template["output_key"] == {
"required": True, "required": True,
@ -124,6 +129,7 @@ def test_llm_math_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": True, "advanced": True,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["_type"] == "LLMMathChain" assert template["_type"] == "LLMMathChain"
@ -163,6 +169,9 @@ def test_series_character_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
"file_path": "",
"value": "",
} }
assert template["character"] == { assert template["character"] == {
"required": True, "required": True,
@ -176,6 +185,9 @@ def test_series_character_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
"file_path": "",
"value": "",
} }
assert template["series"] == { assert template["series"] == {
"required": True, "required": True,
@ -189,6 +201,9 @@ def test_series_character_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
"file_path": "",
"value": "",
} }
assert template["_type"] == "SeriesCharacterChain" assert template["_type"] == "SeriesCharacterChain"
@ -232,6 +247,9 @@ def test_mid_journey_prompt_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"file_path": "",
"fileTypes": [],
"value": "",
} }
# Test the description object # Test the description object
assert chain["description"] == "MidJourneyPromptChain is a chain you can use to generate new MidJourney prompts." assert chain["description"] == "MidJourneyPromptChain is a chain you can use to generate new MidJourney prompts."
@ -270,6 +288,9 @@ def test_time_travel_guide_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"file_path": "",
"fileTypes": [],
"value": "",
} }
assert template["memory"] == { assert template["memory"] == {
"required": False, "required": False,
@ -283,6 +304,9 @@ def test_time_travel_guide_chain(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"file_path": "",
"fileTypes": [],
"value": "",
} }
assert chain["description"] == "Time travel guide chain." assert chain["description"] == "Time travel guide chain."

View file

@ -31,9 +31,9 @@ def test_template_field_defaults(sample_template_field: TemplateField):
assert sample_template_field.is_list is False assert sample_template_field.is_list is False
assert sample_template_field.show is True assert sample_template_field.show is True
assert sample_template_field.multiline is False assert sample_template_field.multiline is False
assert sample_template_field.value is None assert sample_template_field.value == ""
assert sample_template_field.file_types == [] assert sample_template_field.file_types == []
assert sample_template_field.file_path is None assert sample_template_field.file_path == ""
assert sample_template_field.password is False assert sample_template_field.password is False
assert sample_template_field.name == "test_field" assert sample_template_field.name == "test_field"

View file

@ -22,6 +22,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["verbose"] == { assert template["verbose"] == {
"required": False, "required": False,
@ -35,6 +36,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["client"] == { assert template["client"] == {
"required": False, "required": False,
@ -48,6 +50,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["model_name"] == { assert template["model_name"] == {
"required": False, "required": False,
@ -69,6 +72,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": True, "list": True,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
# Add more assertions for other properties here # Add more assertions for other properties here
assert template["temperature"] == { assert template["temperature"] == {
@ -84,6 +88,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["max_tokens"] == { assert template["max_tokens"] == {
"required": False, "required": False,
@ -98,6 +103,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["top_p"] == { assert template["top_p"] == {
"required": False, "required": False,
@ -112,6 +118,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["frequency_penalty"] == { assert template["frequency_penalty"] == {
"required": False, "required": False,
@ -126,6 +133,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["presence_penalty"] == { assert template["presence_penalty"] == {
"required": False, "required": False,
@ -140,6 +148,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["n"] == { assert template["n"] == {
"required": False, "required": False,
@ -154,6 +163,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["best_of"] == { assert template["best_of"] == {
"required": False, "required": False,
@ -168,6 +178,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["model_kwargs"] == { assert template["model_kwargs"] == {
"required": False, "required": False,
@ -181,6 +192,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": True, "advanced": True,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["openai_api_key"] == { assert template["openai_api_key"] == {
"required": False, "required": False,
@ -196,6 +208,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["batch_size"] == { assert template["batch_size"] == {
"required": False, "required": False,
@ -210,6 +223,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["request_timeout"] == { assert template["request_timeout"] == {
"required": False, "required": False,
@ -223,6 +237,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["logit_bias"] == { assert template["logit_bias"] == {
"required": False, "required": False,
@ -236,6 +251,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["max_retries"] == { assert template["max_retries"] == {
"required": False, "required": False,
@ -250,6 +266,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["streaming"] == { assert template["streaming"] == {
"required": False, "required": False,
@ -264,6 +281,7 @@ def test_openai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
@ -289,6 +307,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["client"] == { assert template["client"] == {
"required": False, "required": False,
@ -302,6 +321,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["model_name"] == { assert template["model_name"] == {
"required": False, "required": False,
@ -324,6 +344,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": True, "list": True,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["temperature"] == { assert template["temperature"] == {
"required": False, "required": False,
@ -338,6 +359,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["model_kwargs"] == { assert template["model_kwargs"] == {
"required": False, "required": False,
@ -351,6 +373,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": True, "advanced": True,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["openai_api_key"] == { assert template["openai_api_key"] == {
"required": False, "required": False,
@ -366,6 +389,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["request_timeout"] == { assert template["request_timeout"] == {
"required": False, "required": False,
@ -379,6 +403,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["max_retries"] == { assert template["max_retries"] == {
"required": False, "required": False,
@ -393,6 +418,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["streaming"] == { assert template["streaming"] == {
"required": False, "required": False,
@ -407,6 +433,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["n"] == { assert template["n"] == {
"required": False, "required": False,
@ -421,6 +448,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["max_tokens"] == { assert template["max_tokens"] == {
@ -435,6 +463,7 @@ def test_chat_open_ai(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["_type"] == "ChatOpenAI" assert template["_type"] == "ChatOpenAI"
assert ( assert (

View file

@ -31,6 +31,7 @@ def test_prompt_template(client: TestClient, logged_in_headers):
"list": True, "list": True,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["output_parser"] == { assert template["output_parser"] == {
@ -45,6 +46,7 @@ def test_prompt_template(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["partial_variables"] == { assert template["partial_variables"] == {
@ -59,6 +61,7 @@ def test_prompt_template(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["template"] == { assert template["template"] == {
@ -73,6 +76,7 @@ def test_prompt_template(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["template_format"] == { assert template["template_format"] == {
@ -88,6 +92,7 @@ def test_prompt_template(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }
assert template["validate_template"] == { assert template["validate_template"] == {
@ -103,4 +108,5 @@ def test_prompt_template(client: TestClient, logged_in_headers):
"list": False, "list": False,
"advanced": False, "advanced": False,
"info": "", "info": "",
"fileTypes": [],
} }