Merge branch 'dev' into vecstores
This commit is contained in:
commit
fee2e52ec1
15 changed files with 325 additions and 213 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
from typing import Type, Union
|
||||
|
||||
import pytest
|
||||
from langchain.agents import AgentExecutor
|
||||
|
|
@ -14,6 +15,8 @@ from langflow.graph.nodes import (
|
|||
WrapperNode,
|
||||
)
|
||||
from langflow.utils.payload import build_json, get_root_node
|
||||
from langflow.interface.run import get_result_and_thought_using_graph
|
||||
from langchain.llms.fake import FakeListLLM
|
||||
|
||||
# Test cases for the graph module
|
||||
|
||||
|
|
@ -53,7 +56,7 @@ def openapi_graph():
|
|||
return get_graph("openapi")
|
||||
|
||||
|
||||
def get_node_by_type(graph, node_type):
|
||||
def get_node_by_type(graph, node_type: Type[Node]) -> Union[Node, None]:
|
||||
"""Get a node by type"""
|
||||
return next((node for node in graph.nodes if isinstance(node, node_type)), None)
|
||||
|
||||
|
|
@ -418,3 +421,28 @@ def test_wrapper_node_build(openapi_graph):
|
|||
built_object = wrapper_node.build()
|
||||
assert built_object is not None
|
||||
# Add any further assertions specific to the WrapperNode's build() method
|
||||
|
||||
|
||||
def test_get_result_and_thought(basic_graph):
|
||||
"""Test the get_result_and_thought method"""
|
||||
responses = [
|
||||
"Final Answer: I am a response",
|
||||
]
|
||||
message = "Hello"
|
||||
# Find the node that is an LLMNode and change the
|
||||
# _built_object to a FakeListLLM
|
||||
llm_node = get_node_by_type(basic_graph, LLMNode)
|
||||
assert llm_node is not None
|
||||
llm_node._built_object = FakeListLLM(responses=responses)
|
||||
llm_node._built = True
|
||||
langchain_object = basic_graph.build()
|
||||
# assert all nodes are built
|
||||
assert all(node._built for node in basic_graph.nodes)
|
||||
# now build again and check if FakeListLLM was used
|
||||
|
||||
# Get the result and thought
|
||||
result, thought = get_result_and_thought_using_graph(langchain_object, message)
|
||||
# The result should be a str
|
||||
assert isinstance(result, str)
|
||||
# The thought should be a Thought
|
||||
assert isinstance(thought, str)
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ def test_hugging_face_hub(client: TestClient):
|
|||
assert template["repo_id"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"value": "gpt2",
|
||||
"password": False,
|
||||
|
|
@ -62,19 +62,20 @@ def test_hugging_face_hub(client: TestClient):
|
|||
"list": False,
|
||||
}
|
||||
assert template["task"] == {
|
||||
"required": False,
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"options": ["text-generation", "text2text-generation"],
|
||||
"name": "task",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
"list": True,
|
||||
}
|
||||
assert template["model_kwargs"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"name": "model_kwargs",
|
||||
|
|
@ -82,12 +83,13 @@ def test_hugging_face_hub(client: TestClient):
|
|||
"list": False,
|
||||
}
|
||||
assert template["huggingfacehub_api_token"] == {
|
||||
"required": False,
|
||||
"required": True,
|
||||
"placeholder": "",
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"password": True,
|
||||
"name": "huggingfacehub_api_token",
|
||||
"display_name": "HuggingFace Hub API Token",
|
||||
"type": "str",
|
||||
"list": False,
|
||||
}
|
||||
|
|
@ -231,7 +233,7 @@ def test_openai(client: TestClient):
|
|||
assert template["model_kwargs"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"name": "model_kwargs",
|
||||
|
|
@ -361,7 +363,7 @@ def test_chat_open_ai(client: TestClient):
|
|||
assert template["model_kwargs"] == {
|
||||
"required": False,
|
||||
"placeholder": "",
|
||||
"show": False,
|
||||
"show": True,
|
||||
"multiline": False,
|
||||
"password": False,
|
||||
"name": "model_kwargs",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue