The following changes were made: - Removed the `custom_chain` fixture and the `MyCustomChain` and `CustomChain` classes as they were not being used. - Removed the `data_processing`, `filter_docs`, `get_request`, and `post_request` fixtures as they were not being used. 🔧 fix(test_agents_template.py): set "dynamic" property to False for all template variables to ensure consistency and improve clarity 🐛 fix(test_chains_template.py): add missing "dynamic" field to template dictionaries to ensure consistency and avoid potential bugs 🔧 fix(test_custom_component.py): fix import statements and remove unused imports to improve code readability and maintainability ✨ feat(test_custom_component.py): add tests for the initialization of the CodeParser, Component, and CustomComponent classes 🔧 fix(test_custom_component.py): fix test names and add missing test cases for the Component and CustomComponent classes 🔨 refactor: refactor server.ts to use uppercase PORT variable for improved semantics ✨ feat: add support for process.env.PORT environment variable to run app on configurable port 🔨 refactor: refactor CustomComponent tests for improved readability and maintainability 🔨 refactor: refactor CodeParser tests for improved readability and maintainability 🔨 refactor: refactor Component tests for improved readability and maintainability 🐛 fix: fix CustomComponent class template validation to raise HTTPException when code is None 🔧 fix(tests): fix syntax error in custom_component._class_template_validation ✨ feat(tests): add test_custom_component_get_code_tree_syntax_error to test CustomComponent.get_code_tree method for raising CodeSyntaxError when given incorrect syntax ✨ feat(tests): add test_custom_component_get_function_entrypoint_args_no_args to test CustomComponent.get_function_entrypoint_args property with a build method with no arguments ✨ feat(tests): add test_custom_component_get_function_entrypoint_return_type_no_return_type to test CustomComponent.get_function_entrypoint_return_type property with a build method with no return type ✨ feat(tests): add test_custom_component_get_main_class_name_no_main_class to test CustomComponent.get_main_class_name property when there is no main class ✨ feat(tests): add test_custom_component_build_not_implemented to test CustomComponent.build method for raising NotImplementedError ✨ feat(tests): add fixtures for custom_chain, data_processing, filter_docs, and get_request 🔧 fix(tests): remove commented out code and unused imports to improve code readability and maintainability 🐛 fix(test_llms_template.py): set "dynamic" property to False for all template properties to ensure static values are used 🐛 fix(test_prompts_template.py): set "dynamic" property to False for all template properties to ensure consistency and improve readability
460 lines
12 KiB
Python
460 lines
12 KiB
Python
from fastapi.testclient import TestClient
|
|
from langflow.settings import settings
|
|
|
|
|
|
def test_chains_settings(client: TestClient):
|
|
response = client.get("api/v1/all")
|
|
assert response.status_code == 200
|
|
json_response = response.json()
|
|
chains = json_response["chains"]
|
|
assert set(chains.keys()) == set(settings.chains)
|
|
|
|
|
|
# Test the ConversationChain object
|
|
def test_conversation_chain(client: TestClient):
|
|
response = client.get("api/v1/all")
|
|
assert response.status_code == 200
|
|
json_response = response.json()
|
|
chains = json_response["chains"]
|
|
|
|
chain = chains["ConversationChain"]
|
|
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
|
assert set(chain["base_classes"]) == {
|
|
"ConversationChain",
|
|
"LLMChain",
|
|
"Chain",
|
|
"function",
|
|
}
|
|
|
|
template = chain["template"]
|
|
assert template["memory"] == {
|
|
"required": False,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "memory",
|
|
"type": "BaseMemory",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["verbose"] == {
|
|
"required": False,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": False,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "verbose",
|
|
"type": "bool",
|
|
"list": False,
|
|
"advanced": True,
|
|
"info": "",
|
|
}
|
|
assert template["llm"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "llm",
|
|
"type": "BaseLanguageModel",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["input_key"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"value": "input",
|
|
"password": False,
|
|
"name": "input_key",
|
|
"type": "str",
|
|
"list": False,
|
|
"advanced": True,
|
|
"info": "",
|
|
}
|
|
assert template["output_key"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"value": "response",
|
|
"password": False,
|
|
"name": "output_key",
|
|
"type": "str",
|
|
"list": False,
|
|
"advanced": True,
|
|
"info": "",
|
|
}
|
|
assert template["_type"] == "ConversationChain"
|
|
|
|
# Test the description object
|
|
assert (
|
|
chain["description"]
|
|
== "Chain to have a conversation and load context from memory."
|
|
)
|
|
|
|
|
|
def test_llm_chain(client: TestClient):
|
|
response = client.get("api/v1/all")
|
|
assert response.status_code == 200
|
|
json_response = response.json()
|
|
chains = json_response["chains"]
|
|
chain = chains["LLMChain"]
|
|
|
|
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
|
assert set(chain["base_classes"]) == {
|
|
"function",
|
|
"LLMChain",
|
|
"Chain",
|
|
}
|
|
|
|
template = chain["template"]
|
|
assert template["memory"] == {
|
|
"required": False,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "memory",
|
|
"type": "BaseMemory",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["verbose"] == {
|
|
"required": False,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": False,
|
|
"multiline": False,
|
|
"value": False,
|
|
"password": False,
|
|
"name": "verbose",
|
|
"type": "bool",
|
|
"list": False,
|
|
"advanced": True,
|
|
"info": "",
|
|
}
|
|
assert template["llm"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "llm",
|
|
"type": "BaseLanguageModel",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["output_key"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"value": "text",
|
|
"password": False,
|
|
"name": "output_key",
|
|
"type": "str",
|
|
"list": False,
|
|
"advanced": True,
|
|
"info": "",
|
|
}
|
|
|
|
|
|
def test_llm_checker_chain(client: TestClient):
|
|
response = client.get("api/v1/all")
|
|
assert response.status_code == 200
|
|
json_response = response.json()
|
|
chains = json_response["chains"]
|
|
chain = chains["LLMCheckerChain"]
|
|
|
|
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
|
assert set(chain["base_classes"]) == {
|
|
"function",
|
|
"LLMCheckerChain",
|
|
"Chain",
|
|
}
|
|
|
|
template = chain["template"]
|
|
assert template["llm"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "llm",
|
|
"type": "BaseLanguageModel",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["_type"] == "LLMCheckerChain"
|
|
|
|
# Test the description object
|
|
assert chain["description"] == ""
|
|
|
|
|
|
def test_llm_math_chain(client: TestClient):
|
|
response = client.get("api/v1/all")
|
|
assert response.status_code == 200
|
|
json_response = response.json()
|
|
chains = json_response["chains"]
|
|
|
|
chain = chains["LLMMathChain"]
|
|
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
|
assert set(chain["base_classes"]) == {
|
|
"function",
|
|
"LLMMathChain",
|
|
"Chain",
|
|
}
|
|
|
|
template = chain["template"]
|
|
assert template["memory"] == {
|
|
"required": False,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "memory",
|
|
"type": "BaseMemory",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["verbose"] == {
|
|
"required": False,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": False,
|
|
"multiline": False,
|
|
"value": False,
|
|
"password": False,
|
|
"name": "verbose",
|
|
"type": "bool",
|
|
"list": False,
|
|
"advanced": True,
|
|
"info": "",
|
|
}
|
|
assert template["llm"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "llm",
|
|
"type": "BaseLanguageModel",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["input_key"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"value": "question",
|
|
"password": False,
|
|
"name": "input_key",
|
|
"type": "str",
|
|
"list": False,
|
|
"advanced": True,
|
|
"info": "",
|
|
}
|
|
assert template["output_key"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"value": "answer",
|
|
"password": False,
|
|
"name": "output_key",
|
|
"type": "str",
|
|
"list": False,
|
|
"advanced": True,
|
|
"info": "",
|
|
}
|
|
assert template["_type"] == "LLMMathChain"
|
|
|
|
# Test the description object
|
|
assert (
|
|
chain["description"]
|
|
== "Chain that interprets a prompt and executes python code to do math."
|
|
)
|
|
|
|
|
|
def test_series_character_chain(client: TestClient):
|
|
response = client.get("api/v1/all")
|
|
assert response.status_code == 200
|
|
json_response = response.json()
|
|
chains = json_response["chains"]
|
|
|
|
chain = chains["SeriesCharacterChain"]
|
|
|
|
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
|
|
assert set(chain["base_classes"]) == {
|
|
"function",
|
|
"LLMChain",
|
|
"BaseCustomChain",
|
|
"Chain",
|
|
"ConversationChain",
|
|
"SeriesCharacterChain",
|
|
}
|
|
template = chain["template"]
|
|
|
|
assert template["llm"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"display_name": "LLM",
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "llm",
|
|
"type": "BaseLanguageModel",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["character"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "character",
|
|
"type": "str",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["series"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "series",
|
|
"type": "str",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["_type"] == "SeriesCharacterChain"
|
|
|
|
# Test the description object
|
|
assert (
|
|
chain["description"]
|
|
== "SeriesCharacterChain is a chain you can use to have a conversation with a character from a series."
|
|
)
|
|
|
|
|
|
def test_mid_journey_prompt_chain(client: TestClient):
|
|
response = client.get("api/v1/all")
|
|
assert response.status_code == 200
|
|
json_response = response.json()
|
|
chains = json_response["chains"]
|
|
chain = chains["MidJourneyPromptChain"]
|
|
assert isinstance(chain, dict)
|
|
|
|
# Test the base_classes object
|
|
assert set(chain["base_classes"]) == {
|
|
"LLMChain",
|
|
"BaseCustomChain",
|
|
"Chain",
|
|
"ConversationChain",
|
|
"MidJourneyPromptChain",
|
|
}
|
|
|
|
# Test the template object
|
|
template = chain["template"]
|
|
|
|
assert template["llm"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"display_name": "LLM",
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "llm",
|
|
"type": "BaseLanguageModel",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
# Test the description object
|
|
assert (
|
|
chain["description"]
|
|
== "MidJourneyPromptChain is a chain you can use to generate new MidJourney prompts."
|
|
)
|
|
|
|
|
|
def test_time_travel_guide_chain(client: TestClient):
|
|
response = client.get("api/v1/all")
|
|
assert response.status_code == 200
|
|
json_response = response.json()
|
|
chains = json_response["chains"]
|
|
chain = chains["TimeTravelGuideChain"]
|
|
assert isinstance(chain, dict)
|
|
|
|
# Test the base_classes object
|
|
assert set(chain["base_classes"]) == {
|
|
"LLMChain",
|
|
"BaseCustomChain",
|
|
"TimeTravelGuideChain",
|
|
"Chain",
|
|
"ConversationChain",
|
|
}
|
|
|
|
# Test the template object
|
|
template = chain["template"]
|
|
|
|
assert template["llm"] == {
|
|
"required": True,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"display_name": "LLM",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "llm",
|
|
"type": "BaseLanguageModel",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
assert template["memory"] == {
|
|
"required": False,
|
|
"dynamic": False,
|
|
"placeholder": "",
|
|
"show": True,
|
|
"multiline": False,
|
|
"password": False,
|
|
"name": "memory",
|
|
"type": "BaseChatMemory",
|
|
"list": False,
|
|
"advanced": False,
|
|
"info": "",
|
|
}
|
|
|
|
assert chain["description"] == "Time travel guide chain."
|