Skip to content

Commit

Permalink
Formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hsin-c committed May 16, 2024
1 parent 4b96c64 commit d682732
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 6 additions & 5 deletions morpheus/llm/nodes/langchain_agent_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class LangChainAgentNode(LLMNodeBase):
The agent executor to use to execute.
"""

def __init__(self, agent_executor: "AgentExecutor", replace_exceptions: bool=False, replace_exceptions_value: typing.Optional[str]=None):
def __init__(self,
agent_executor: "AgentExecutor",
replace_exceptions: bool = False,
replace_exceptions_value: typing.Optional[str] = None):
super().__init__()

self._agent_executor = agent_executor
Expand Down Expand Up @@ -94,10 +97,8 @@ async def execute(self, context: LLMContext) -> LLMContext: # pylint: disable=i
# If the agent encounters a parsing error or a server error after retries, replace the error
# with a default value to prevent the pipeline from crashing
results[i][j] = self._replace_exceptions_value
logger.warning(
f"Exception encountered in result[{i}][{j}]: {answer}. "
f"Replacing with default message: \"{self._replace_exceptions_value}\"."
)
logger.warning(f"Exception encountered in result[{i}][{j}]: {answer}. "
f"Replacing with default message: \"{self._replace_exceptions_value}\".")

context.set_output(results)

Expand Down
7 changes: 3 additions & 4 deletions tests/llm/nodes/test_langchain_agent_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def test_execute_error(mock_chat_completion: tuple[mock.MagicMock, mock.MagicMoc
node = LangChainAgentNode(agent_executor=agent)
assert isinstance(execute_node(node, input="input1"), RuntimeError)


@pytest.mark.parametrize(
"arun_return,expected_output",
[
Expand All @@ -164,9 +165,7 @@ def test_execute_replaces_exceptions(
arun_return: list,
expected_output: list,
):
placeholder_input_values = {
"foo": "bar"
} # a non-empty placeholder input for the context
placeholder_input_values = {"foo": "bar"} # a non-empty placeholder input for the context
mock_agent_executor.arun.return_value = arun_return

node = LangChainAgentNode(
Expand All @@ -175,4 +174,4 @@ def test_execute_replaces_exceptions(
replace_exceptions_value="Default error message.",
)
output = execute_node(node, **placeholder_input_values)
assert output == expected_output
assert output == expected_output

0 comments on commit d682732

Please sign in to comment.