From 84a66bc981a9760e4c28e533e73539a2d3ba50b5 Mon Sep 17 00:00:00 2001 From: Kye Date: Mon, 16 Oct 2023 23:18:13 -0400 Subject: [PATCH] swarms Former-commit-id: 7fd7ebd9da6a5d3c7cd2ac60970ab05a0d5ed4a0 --- pyproject.toml | 1 + requirements.txt | 1 + stacked_worker.py | 2 +- swarms/utils/__init__.py | 2 ++ swarms/utils/display_markdown.py | 22 ++++++++++++++++++++++ swarms/workers/worker.py | 6 +++--- 6 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 swarms/utils/display_markdown.py diff --git a/pyproject.toml b/pyproject.toml index 1b52584e..2eec0501 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ termcolor = "*" black = "*" dalle3 = "*" torchvision = "*" +rich = "*" [tool.poetry.dev-dependencies] diff --git a/requirements.txt b/requirements.txt index 0a5e93ae..8a74aadd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -53,6 +53,7 @@ yapf autopep8 dalle3 torchvision +rich mkdocs diff --git a/stacked_worker.py b/stacked_worker.py index c28f343c..6498cba0 100644 --- a/stacked_worker.py +++ b/stacked_worker.py @@ -110,7 +110,7 @@ node = Worker( ) # Specify task -task = "What were the winning boston marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times." +task = "Create a neural network using the interpreter tool" # Run the node on the task response = node.run(task) diff --git a/swarms/utils/__init__.py b/swarms/utils/__init__.py index 24cbad0b..1870b356 100644 --- a/swarms/utils/__init__.py +++ b/swarms/utils/__init__.py @@ -2,3 +2,5 @@ # from swarms.utils.logger import logger # from swarms.utils.utils import FileType, AbstractUploader, StaticUploader, BaseHandler, FileHandler, CsvToDataframe """Swarms utils""" +from swarms.utils.display_markdown import display_markdown_message +from swarms.utils.futures import execute_futures_dict diff --git a/swarms/utils/display_markdown.py b/swarms/utils/display_markdown.py new file mode 100644 index 00000000..9d06d2bb --- /dev/null +++ b/swarms/utils/display_markdown.py @@ -0,0 +1,22 @@ +from rich import print as rich_print +from rich.markdown import Markdown +from rich.rule import Rule + +def display_markdown_message(message): + """ + Display markdown message. Works with multiline strings with lots of indentation. + Will automatically make single line > tags beautiful. + """ + + for line in message.split("\n"): + line = line.strip() + if line == "": + print("") + elif line == "---": + rich_print(Rule(style="white")) + else: + rich_print(Markdown(line)) + + if "\n" not in message and message.startswith(">"): + # Aesthetic choice. For these tags, they need a space below them + print("") \ No newline at end of file diff --git a/swarms/workers/worker.py b/swarms/workers/worker.py index 127826ab..e7745890 100644 --- a/swarms/workers/worker.py +++ b/swarms/workers/worker.py @@ -180,7 +180,7 @@ class Worker: except Exception as error: raise RuntimeError(f"Error setting up agent: {error}") - @log_decorator + # @log_decorator @error_decorator @timing_decorator def run(self, task: str = None): @@ -199,7 +199,7 @@ class Worker: except Exception as error: raise RuntimeError(f"Error while running agent: {error}") - @log_decorator + # @log_decorator @error_decorator @timing_decorator def __call__(self, task: str = None): @@ -221,7 +221,7 @@ class Worker: def health_check(self): pass - @log_decorator + # @log_decorator @error_decorator @timing_decorator def chat(self, msg: str = None, streaming: bool = False):