Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
whimo committed Jul 7, 2024
1 parent da83ceb commit dc81493
Show file tree
Hide file tree
Showing 23 changed files with 26 additions and 8 deletions.
10 changes: 9 additions & 1 deletion motleycrew/agents/output_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ class MotleyOutputHandler(MotleyTool, ABC):
"""Exceptions that should be returned to the agent when raised in the `handle_output` method."""

def __init__(self, max_iterations: int = Defaults.DEFAULT_OUTPUT_HANDLER_MAX_ITERATIONS):
self.max_iterations = max_iterations # number of iterations of catching an exception
"""Initialize the output handler tool.
Args:
max_iterations (int): Maximum number of iterations to run the output handler.
If an exception is raised in the `handle_output` method, the output handler will return
the exception to the agent unless the number of iterations exceeds `max_iterations`,
in which case the output handler will raise OutputHandlerMaxIterationsExceeded.
"""
self.max_iterations = max_iterations
langchain_tool = self._create_langchain_tool()
super().__init__(langchain_tool)

Expand Down
6 changes: 5 additions & 1 deletion motleycrew/agents/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ def handle_agent_output(*args, **kwargs):
except exceptions_to_handle as exc:
if iteration <= max_iterations:
return f"{exc.__class__.__name__}: {str(exc)}"
raise OutputHandlerMaxIterationsExceeded(*args, **kwargs)
raise OutputHandlerMaxIterationsExceeded(
last_call_args=args,
last_call_kwargs=kwargs,
last_exception=exc,
)

raise DirectOutput(output)

Expand Down
14 changes: 10 additions & 4 deletions motleycrew/common/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Module description"""

from typing import Any, Optional
from typing import Any, Dict, Optional

from motleycrew.common import Defaults

Expand Down Expand Up @@ -147,9 +147,15 @@ class InvalidOutput(Exception):
class OutputHandlerMaxIterationsExceeded(BaseException):
"""Raised when the output handlers iteration limit is exceeded"""

def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
def __init__(
self,
last_call_args: tuple,
last_call_kwargs: Dict[str, Any],
last_exception: Exception,
):
self.last_call_args = last_call_args
self.last_call_kwargs = last_call_kwargs
self.last_exception = last_exception

def __str__(self):
return "Maximum number of output handler iterations exceeded"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"def bubble_sort(arr):\n n = len(arr)\n for i in range(n):\n swapped = False\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n arr[j], arr[j+1] = arr[j+1], arr[j]\n swapped = True\n if not swapped:\n break\n return arr\n\n# Test the bubble sort function\nsample_array = [64, 34, 25, 12, 22, 11, 90]\nsorted_array = bubble_sort(sample_array)\nprint(sorted_array)\n\nThe `bubble_sort` function sorts an array using the bubble sort algorithm. It works by repeatedly stepping through the list, comparing adjacent elements and swapping them if they are in the wrong order. This process is repeated until the list is sorted. The outer loop runs `n` times, where `n` is the length of the array, and the inner loop runs `n-i-1` times to avoid re-checking the already sorted elements. An optimization is added by using a `swapped` flag to detect if any swaps were made during an iteration. If no swaps were made, the array is already sorted, and the algorithm can terminate early. The test case demonstrates the function by sorting a sample array."
"def bubble_sort(arr):\n n = len(arr)\n for i in range(n):\n swapped = False\n for j in range(0, n-i-1):\n if arr[j] > arr[j+1]:\n arr[j], arr[j+1] = arr[j+1], arr[j]\n swapped = True\n if not swapped:\n break\n return arr\n\n# Test the bubble sort function\nsample_array = [64, 34, 25, 12, 22, 11, 90]\nsorted_array = bubble_sort(sample_array)\nprint(sorted_array)\n\nThe `bubble_sort` function sorts an array using the bubble sort algorithm. It works by repeatedly stepping through the list, comparing adjacent elements and swapping them if they are in the wrong order. This process is repeated until the list is sorted. The outer loop runs `n` times, where `n` is the length of the array. The inner loop runs `n-i-1` times to avoid re-checking the already sorted elements. An optimization is added by using a `swapped` flag to detect if any swaps were made during an iteration. If no swaps were made, the list is already sorted, and the algorithm can terminate early. The test case demonstrates the function by sorting a sample array."
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"\\[\n\\begin{aligned}\nx &= \\frac{367}{71} \\\\\ny &= -\\frac{25}{49} \\\\\nx - y &= 2\n\\end{aligned}\n\\]"
"To solve the system of linear equations given by:\n\n\\[ 725x + 727y = 1500 \\]\n\\[ 729x + 731y = 1508 \\]\n\nwe first set up the equations and solve them using the sympy library. The solutions are:\n\n\\[ x = -23 \\]\n\\[ y = 25 \\]\n\nTo find \\( x - y \\):\n\n\\[ x - y = -23 - 25 = -48 \\]\n\nThus, the values are:\n\n\\[ x = -23 \\]\n\\[ y = 25 \\]\n\\[ x - y = -48 \\]\n```"

0 comments on commit dc81493

Please sign in to comment.