fix: tests
This commit is contained in:
parent
1c35179aec
commit
8d5adbf266
3 changed files with 138 additions and 295 deletions
|
|
@ -15,6 +15,11 @@ CUSTOM_NODES = {
|
|||
"utilities": {
|
||||
"SQLDatabase": nodes.SQLDatabaseNode(),
|
||||
},
|
||||
"chains": {
|
||||
"SeriesCharacterChain": nodes.SeriesCharacterChainNode(),
|
||||
"TimeTravelGuideChain": nodes.TimeTravelGuideChainNode(),
|
||||
"MidJourneyPromptChain": nodes.MidJourneyPromptChainNode(),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,107 @@ class PythonFunctionNode(FrontendNode):
|
|||
return super().to_dict()
|
||||
|
||||
|
||||
class MidJourneyPromptChainNode(FrontendNode):
|
||||
name: str = "MidJourneyPromptChain"
|
||||
template: Template = Template(
|
||||
type_name="MidJourneyPromptChain",
|
||||
fields=[
|
||||
TemplateField(
|
||||
field_type="BaseLanguageModel",
|
||||
required=True,
|
||||
placeholder="",
|
||||
is_list=False,
|
||||
show=True,
|
||||
advanced=False,
|
||||
multiline=False,
|
||||
name="llm",
|
||||
),
|
||||
],
|
||||
)
|
||||
description: str = "MidJourneyPromptChain is a chain you can use to generate new MidJourney prompts."
|
||||
base_classes: list[str] = [
|
||||
"LLMChain",
|
||||
"BaseCustomChain",
|
||||
"Chain",
|
||||
"ConversationChain",
|
||||
"MidJourneyPromptChain",
|
||||
]
|
||||
|
||||
|
||||
class TimeTravelGuideChainNode(FrontendNode):
|
||||
name: str = "TimeTravelGuideChain"
|
||||
template: Template = Template(
|
||||
type_name="TimeTravelGuideChain",
|
||||
fields=[
|
||||
TemplateField(
|
||||
field_type="BaseLanguageModel",
|
||||
required=True,
|
||||
placeholder="",
|
||||
is_list=False,
|
||||
show=True,
|
||||
advanced=False,
|
||||
multiline=False,
|
||||
name="llm",
|
||||
),
|
||||
],
|
||||
)
|
||||
description: str = "Time travel guide chain to be used in the flow."
|
||||
base_classes: list[str] = [
|
||||
"LLMChain",
|
||||
"BaseCustomChain",
|
||||
"TimeTravelGuideChain",
|
||||
"Chain",
|
||||
"ConversationChain",
|
||||
]
|
||||
|
||||
|
||||
class SeriesCharacterChainNode(FrontendNode):
|
||||
name: str = "SeriesCharacterChain"
|
||||
template: Template = Template(
|
||||
type_name="SeriesCharacterChain",
|
||||
fields=[
|
||||
TemplateField(
|
||||
field_type="str",
|
||||
required=True,
|
||||
placeholder="",
|
||||
is_list=False,
|
||||
show=True,
|
||||
advanced=False,
|
||||
multiline=False,
|
||||
name="character",
|
||||
),
|
||||
TemplateField(
|
||||
field_type="str",
|
||||
required=True,
|
||||
placeholder="",
|
||||
is_list=False,
|
||||
show=True,
|
||||
advanced=False,
|
||||
multiline=False,
|
||||
name="series",
|
||||
),
|
||||
TemplateField(
|
||||
field_type="BaseLanguageModel",
|
||||
required=True,
|
||||
placeholder="",
|
||||
is_list=False,
|
||||
show=True,
|
||||
advanced=False,
|
||||
multiline=False,
|
||||
name="llm",
|
||||
),
|
||||
],
|
||||
)
|
||||
description: str = "SeriesCharacterChain is a chain you can use to have a conversation with a character from a series." # noqa
|
||||
base_classes: list[str] = [
|
||||
"LLMChain",
|
||||
"BaseCustomChain",
|
||||
"Chain",
|
||||
"ConversationChain",
|
||||
"SeriesCharacterChain",
|
||||
]
|
||||
|
||||
|
||||
class ToolNode(FrontendNode):
|
||||
name: str = "Tool"
|
||||
template: Template = Template(
|
||||
|
|
@ -418,17 +519,29 @@ class ChainFrontendNode(FrontendNode):
|
|||
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
|
||||
FrontendNode.format_field(field, name)
|
||||
|
||||
field.advanced = False
|
||||
if "key" in field.name:
|
||||
field.password = False
|
||||
field.show = False
|
||||
if field.name in ["input_key", "output_key"]:
|
||||
field.required = True
|
||||
field.show = True
|
||||
field.advanced = True
|
||||
|
||||
# Separated for possible future changes
|
||||
if field.name == "prompt":
|
||||
# if no prompt is provided, use the default prompt
|
||||
field.required = False
|
||||
field.show = True
|
||||
field.advanced = False
|
||||
if field.name == "memory":
|
||||
field.required = False
|
||||
field.show = True
|
||||
field.advanced = False
|
||||
if field.name == "verbose":
|
||||
field.required = False
|
||||
field.show = True
|
||||
field.advanced = True
|
||||
|
||||
|
||||
class LLMFrontendNode(FrontendNode):
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ def test_conversation_chain(client: TestClient):
|
|||
"name": "memory",
|
||||
"type": "BaseMemory",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["verbose"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"name": "verbose",
|
||||
|
|
@ -53,7 +53,7 @@ def test_conversation_chain(client: TestClient):
|
|||
"name": "llm",
|
||||
"type": "BaseLanguageModel",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["input_key"] == {
|
||||
"required": True,
|
||||
|
|
@ -107,12 +107,12 @@ def test_llm_chain(client: TestClient):
|
|||
"name": "memory",
|
||||
"type": "BaseMemory",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["verbose"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": False,
|
||||
"password": False,
|
||||
|
|
@ -130,7 +130,7 @@ def test_llm_chain(client: TestClient):
|
|||
"name": "llm",
|
||||
"type": "BaseLanguageModel",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["output_key"] == {
|
||||
"required": True,
|
||||
|
|
@ -165,12 +165,12 @@ def test_llm_checker_chain(client: TestClient):
|
|||
"name": "memory",
|
||||
"type": "BaseMemory",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["verbose"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": False,
|
||||
"password": False,
|
||||
|
|
@ -188,7 +188,7 @@ def test_llm_checker_chain(client: TestClient):
|
|||
"name": "llm",
|
||||
"type": "BaseLLM",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["input_key"] == {
|
||||
"required": True,
|
||||
|
|
@ -242,12 +242,12 @@ def test_llm_math_chain(client: TestClient):
|
|||
"name": "memory",
|
||||
"type": "BaseMemory",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["verbose"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": False,
|
||||
"password": False,
|
||||
|
|
@ -265,7 +265,7 @@ def test_llm_math_chain(client: TestClient):
|
|||
"name": "llm",
|
||||
"type": "BaseLanguageModel",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["input_key"] == {
|
||||
"required": True,
|
||||
|
|
@ -317,37 +317,7 @@ def test_series_character_chain(client: TestClient):
|
|||
"SeriesCharacterChain",
|
||||
}
|
||||
template = chain["template"]
|
||||
assert template["memory"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": {
|
||||
"chat_memory": {"messages": []},
|
||||
"output_key": None,
|
||||
"input_key": None,
|
||||
"return_messages": False,
|
||||
"human_prefix": "Human",
|
||||
"ai_prefix": "AI",
|
||||
"memory_key": "history",
|
||||
},
|
||||
"password": False,
|
||||
"name": "memory",
|
||||
"type": "BaseMemory",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["verbose"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"name": "verbose",
|
||||
"type": "bool",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
|
||||
assert template["llm"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
|
|
@ -357,55 +327,7 @@ def test_series_character_chain(client: TestClient):
|
|||
"name": "llm",
|
||||
"type": "BaseLanguageModel",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["input_key"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": "input",
|
||||
"password": False,
|
||||
"name": "input_key",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["output_key"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": "response",
|
||||
"password": False,
|
||||
"name": "output_key",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["template"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"multiline": True,
|
||||
"value": "I want you to act like {character} from {series}.\nI want you to respond and answer like {character}. do not write any explanations. only answer like {character}.\nYou must know all of the knowledge of {character}.\nCurrent conversation:\n{history}\nHuman: {input}\n{character}:", # noqa: E501
|
||||
"password": False,
|
||||
"name": "template",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["ai_prefix_value"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"multiline": False,
|
||||
"value": "character",
|
||||
"password": False,
|
||||
"name": "ai_prefix_value",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["character"] == {
|
||||
"required": True,
|
||||
|
|
@ -416,7 +338,7 @@ def test_series_character_chain(client: TestClient):
|
|||
"name": "character",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["series"] == {
|
||||
"required": True,
|
||||
|
|
@ -427,7 +349,7 @@ def test_series_character_chain(client: TestClient):
|
|||
"name": "series",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
assert template["_type"] == "SeriesCharacterChain"
|
||||
|
||||
|
|
@ -457,58 +379,7 @@ def test_mid_journey_prompt_chain(client: TestClient):
|
|||
|
||||
# Test the template object
|
||||
template = chain["template"]
|
||||
assert template["memory"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": {
|
||||
"chat_memory": {"messages": []},
|
||||
"output_key": None,
|
||||
"input_key": None,
|
||||
"return_messages": False,
|
||||
"human_prefix": "Human",
|
||||
"ai_prefix": "AI",
|
||||
"memory_key": "history",
|
||||
},
|
||||
"password": False,
|
||||
"name": "memory",
|
||||
"type": "BaseMemory",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["verbose"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"name": "verbose",
|
||||
"type": "bool",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
# Continue with other template object assertions
|
||||
assert template["prompt"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": {
|
||||
"input_variables": ["history", "input"],
|
||||
"output_parser": None,
|
||||
"partial_variables": {},
|
||||
"template": "The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n\nCurrent conversation:\n{history}\nHuman: {input}\nAI:", # noqa: E501
|
||||
"template_format": "f-string",
|
||||
"validate_template": True,
|
||||
"_type": "prompt",
|
||||
},
|
||||
"password": False,
|
||||
"name": "prompt",
|
||||
"type": "BasePromptTemplate",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
|
||||
assert template["llm"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
|
|
@ -518,54 +389,7 @@ def test_mid_journey_prompt_chain(client: TestClient):
|
|||
"name": "llm",
|
||||
"type": "BaseLanguageModel",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["output_key"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": "response",
|
||||
"password": False,
|
||||
"name": "output_key",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["input_key"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": "input",
|
||||
"password": False,
|
||||
"name": "input_key",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["template"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"multiline": True,
|
||||
"value": 'I want you to act as a prompt generator for Midjourney\'s artificial intelligence program.\n Your job is to provide detailed and creative descriptions that will inspire unique and interesting images from the AI.\n Keep in mind that the AI is capable of understanding a wide range of language and can interpret abstract concepts, so feel free to be as imaginative and descriptive as possible.\n For example, you could describe a scene from a futuristic city, or a surreal landscape filled with strange creatures.\n The more detailed and imaginative your description, the more interesting the resulting image will be. Here is your first prompt:\n "A field of wildflowers stretches out as far as the eye can see, each one a different color and shape. In the distance, a massive tree towers over the landscape, its branches reaching up to the sky like tentacles."\n\n Current conversation:\n {history}\n Human: {input}\n AI:', # noqa: E501
|
||||
"password": False,
|
||||
"name": "template",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["ai_prefix_value"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"name": "ai_prefix_value",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
# Test the description object
|
||||
assert (
|
||||
|
|
@ -593,58 +417,7 @@ def test_time_travel_guide_chain(client: TestClient):
|
|||
|
||||
# Test the template object
|
||||
template = chain["template"]
|
||||
assert template["memory"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": {
|
||||
"chat_memory": {"messages": []},
|
||||
"output_key": None,
|
||||
"input_key": None,
|
||||
"return_messages": False,
|
||||
"human_prefix": "Human",
|
||||
"ai_prefix": "AI",
|
||||
"memory_key": "history",
|
||||
},
|
||||
"password": False,
|
||||
"name": "memory",
|
||||
"type": "BaseMemory",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["verbose"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"name": "verbose",
|
||||
"type": "bool",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
|
||||
assert template["prompt"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": {
|
||||
"input_variables": ["history", "input"],
|
||||
"output_parser": None,
|
||||
"partial_variables": {},
|
||||
"template": "The following is a friendly conversation between a human and an AI. The AI is talkative and provides lots of specific details from its context. If the AI does not know the answer to a question, it truthfully says it does not know.\n\nCurrent conversation:\n{history}\nHuman: {input}\nAI:", # noqa: E501
|
||||
"template_format": "f-string",
|
||||
"validate_template": True,
|
||||
"_type": "prompt",
|
||||
},
|
||||
"password": False,
|
||||
"name": "prompt",
|
||||
"type": "BasePromptTemplate",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["llm"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
|
|
@ -654,55 +427,7 @@ def test_time_travel_guide_chain(client: TestClient):
|
|||
"name": "llm",
|
||||
"type": "BaseLanguageModel",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["output_key"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": "response",
|
||||
"password": False,
|
||||
"name": "output_key",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
"advanced": False,
|
||||
}
|
||||
|
||||
assert template["input_key"] == {
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": "input",
|
||||
"password": False,
|
||||
"name": "input_key",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
|
||||
assert template["template"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"multiline": True,
|
||||
"value": "I want you to act as my time travel guide. You are helpful and creative. I will provide you with the historical period or future time I want to visit and you will suggest the best events, sights, or people to experience. Provide the suggestions and any necessary information.\n Current conversation:\n {history}\n Human: {input}\n AI:", # noqa: E501
|
||||
"password": False,
|
||||
"name": "template",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert template["ai_prefix_value"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"name": "ai_prefix_value",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"advanced": True,
|
||||
}
|
||||
assert chain["description"] == ""
|
||||
assert chain["description"] == "Time travel guide chain to be used in the flow."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue