Skip to content

Commit

Permalink
Update function base classes to use Callable
Browse files Browse the repository at this point in the history
instead of function
  • Loading branch information
ogabrielluiz committed Nov 3, 2023
1 parent 5c5ef22 commit d87b622
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/backend/langflow/interface/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
field_type="BaseLanguageModel", required=True, is_list=False, show=True
),
"func": TemplateField(
field_type="function",
field_type="Callable",
required=True,
is_list=False,
show=True,
Expand Down Expand Up @@ -126,7 +126,7 @@ def get_signature(self, name: str) -> Optional[Dict]:
elif tool_type in CUSTOM_TOOLS:
# Get custom tool params
params = self.type_to_loader_dict[name]["params"] # type: ignore
base_classes = ["function"]
base_classes = ["Callable"]
if node := customs.get_custom_nodes("tools").get(tool_type):
return node
elif tool_type in FILE_TOOLS:
Expand Down
2 changes: 1 addition & 1 deletion src/backend/langflow/template/frontend_node/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class InitializeAgentNode(FrontendNode):
],
)
description: str = """Construct a zero shot agent from an LLM and tools."""
base_classes: list[str] = ["AgentExecutor", "function"]
base_classes: list[str] = ["AgentExecutor", "Callable"]

def to_dict(self):
return super().to_dict()
Expand Down
4 changes: 2 additions & 2 deletions src/backend/langflow/template/frontend_node/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class SeriesCharacterChainNode(FrontendNode):
"Chain",
"ConversationChain",
"SeriesCharacterChain",
"function",
"Callable",
]


Expand Down Expand Up @@ -241,7 +241,7 @@ class CombineDocsChainNode(FrontendNode):
],
)
description: str = """Load question answering chain."""
base_classes: list[str] = ["BaseCombineDocumentsChain", "function"]
base_classes: list[str] = ["BaseCombineDocumentsChain", "Callable"]

def to_dict(self):
return super().to_dict()
Expand Down
4 changes: 2 additions & 2 deletions src/backend/langflow/template/frontend_node/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ToolNode(FrontendNode):
),
TemplateField(
name="func",
field_type="function",
field_type="Callable",
required=True,
is_list=False,
show=True,
Expand Down Expand Up @@ -135,7 +135,7 @@ class PythonFunctionNode(FrontendNode):
],
)
description: str = "Python function to be executed."
base_classes: list[str] = ["function"]
base_classes: list[str] = ["Callable"]

def to_dict(self):
return super().to_dict()
6 changes: 3 additions & 3 deletions src/backend/langflow/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def build_template_from_function(
# the output to be a function
base_classes = get_base_classes(_class)
if add_function:
base_classes.append("function")
base_classes.append("Callable")

return {
"template": format_dict(variables, name),
Expand Down Expand Up @@ -114,7 +114,7 @@ def build_template_from_class(
# Adding function to base classes to allow
# the output to be a function
if add_function:
base_classes.append("function")
base_classes.append("Callable")
return {
"template": format_dict(variables, name),
"description": docs.short_description or "",
Expand Down Expand Up @@ -178,7 +178,7 @@ def build_template_from_method(

# Adding function to base classes to allow the output to be a function
if add_function:
base_classes.append("function")
base_classes.append("Callable")

return {
"template": format_dict(variables, class_name),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_agents_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_zero_shot_agent(client: TestClient, logged_in_headers):
"ZeroShotAgent",
"BaseSingleActionAgent",
"Agent",
"function",
"Callable",
}
template = zero_shot_agent["template"]

Expand Down Expand Up @@ -202,7 +202,7 @@ def test_initialize_agent(client: TestClient, logged_in_headers):
agents = json_response["agents"]

initialize_agent = agents["AgentInitializer"]
assert initialize_agent["base_classes"] == ["AgentExecutor", "function"]
assert initialize_agent["base_classes"] == ["AgentExecutor", "Callable"]
template = initialize_agent["template"]

assert template["agent"] == {
Expand Down
10 changes: 5 additions & 5 deletions tests/test_chains_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_conversation_chain(client: TestClient, logged_in_headers):
"ConversationChain",
"LLMChain",
"Chain",
"function",
"Callable",
}

template = chain["template"]
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_llm_chain(client: TestClient, logged_in_headers):

# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
assert set(chain["base_classes"]) == {
"function",
"Callable",
"LLMChain",
"Chain",
}
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_llm_checker_chain(client: TestClient, logged_in_headers):

# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
assert set(chain["base_classes"]) == {
"function",
"Callable",
"LLMCheckerChain",
"Chain",
}
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_llm_math_chain(client: TestClient, logged_in_headers):
chain = chains["LLMMathChain"]
# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
assert set(chain["base_classes"]) == {
"function",
"Callable",
"LLMMathChain",
"Chain",
}
Expand Down Expand Up @@ -309,7 +309,7 @@ def test_series_character_chain(client: TestClient, logged_in_headers):

# Test the base classes, template, memory, verbose, llm, input_key, output_key, and _type objects
assert set(chain["base_classes"]) == {
"function",
"Callable",
"LLMChain",
"BaseCustomChain",
"Chain",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_build_template_from_function():
"ExampleClass1", type_to_loader_dict, add_function=True
)
assert result_with_function is not None
assert "function" in result_with_function["base_classes"]
assert "Callable" in result_with_function["base_classes"]

# Test with invalid name
with pytest.raises(ValueError, match=r".* not found"):
Expand Down

0 comments on commit d87b622

Please sign in to comment.