From 0d10bd1b9e82e3e865b310654d5592afd706ba68 Mon Sep 17 00:00:00 2001 From: Kye Date: Thu, 3 Aug 2023 12:08:57 -0400 Subject: [PATCH] helpers organization in developers tools Former-commit-id: f2d8dd30e25dad5dcdec3a5e7a69e4a1e892cdd6 --- DOCS/Design/CLEAN_CODE.md | 19 +++++++++++++++++++ swarms/agents/__init__.py | 2 +- swarms/agents/tools/developer.py | 32 ++++++++++++++++++-------------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/DOCS/Design/CLEAN_CODE.md b/DOCS/Design/CLEAN_CODE.md index 6707b1ff..7840a649 100644 --- a/DOCS/Design/CLEAN_CODE.md +++ b/DOCS/Design/CLEAN_CODE.md @@ -30,6 +30,13 @@ _____________________________________ 4. Use searchable names. 5. Replace magic numbers with named constants. 6. Avoid encodings. Don't append prefixes or type information. +7. The Name of a variable, Function, or Class should answer why it exists, what it does , and how it can used. Comments are a burden +8. Clarity is King +9. ClassNames should not be a verb +10. Methods should have verb or verb phrase names +11. Be simple. Be Direct. Say what you mean, mean what you say. +12. Don't use the same word for 2 purposes +13. ## Functions rules 1. Small. @@ -38,6 +45,18 @@ _____________________________________ 4. Prefer fewer arguments. 5. Have no side effects. 6. Don't use flag arguments. Split method into several independent methods that can be called from the client without the flag. +7. Smaller than 20 lines long +8. The Stepdown rule => function -> next level of abstraction + + +## ErrorHandling +1. Specify where the error in print +2. Don't use a single variable +3. + +## If statements +1. + ## Comments rules 1. Always try to explain yourself in code. diff --git a/swarms/agents/__init__.py b/swarms/agents/__init__.py index 42200420..5a587667 100644 --- a/swarms/agents/__init__.py +++ b/swarms/agents/__init__.py @@ -7,7 +7,7 @@ #tools from swarms.agents.tools.base import BaseTool, Tool, StructuredTool, ToolWrapper, BaseToolSet, ToolCreator, GlobalToolsCreator, SessionToolsCreator, ToolsFactory -from swarms.agents.tools.autogpt import pushd, process_csv, async_load_playwright, run_async, browse_web_page, WebpageQATool, web_search +from swarms.agents.tools.autogpt import pushd, process_csv, async_load_playwright, run_async, browse_web_page, WebpageQATool, web_search, query_website_tool from swarms.agents.tools.exit_conversation import ExitConversation from swarms.agents.tools.models import MaskFormer, ImageEditing, InstructPix2Pix, Text2Image, VisualQuestionAnswering, ImageCaptioning diff --git a/swarms/agents/tools/developer.py b/swarms/agents/tools/developer.py index 17ebb54d..2ec25e21 100644 --- a/swarms/agents/tools/developer.py +++ b/swarms/agents/tools/developer.py @@ -25,6 +25,24 @@ from swarms.utils.logger import logger from swarms.utils.main import ANSI, Color, Style # test +#helpers +PipeType = Union[Literal["stdout"], Literal["stderr"]] + + +def verify(func): + def wrapper(*args, **kwargs): + try: + filepath = args[0].filepath + except AttributeError: + raise Exception("This tool doesn't have filepath. Please check your code.") + if not str(Path(filepath).resolve()).startswith(str(Path().resolve())): + return "You can't access file outside of playground." + return func(*args, **kwargs) + + return wrapper + + + class SyscallTimeoutException(Exception): def __init__(self, pid: int, *args) -> None: super().__init__(f"deadline exceeded while waiting syscall for {pid}", *args) @@ -114,7 +132,6 @@ class SyscallTracer: return exitcode, reason -PipeType = Union[Literal["stdout"], Literal["stderr"]] class StdoutTracer: @@ -224,19 +241,6 @@ class Terminal(BaseToolSet): -def verify(func): - def wrapper(*args, **kwargs): - try: - filepath = args[0].filepath - except AttributeError: - raise Exception("This tool doesn't have filepath. Please check your code.") - if not str(Path(filepath).resolve()).startswith(str(Path().resolve())): - return "You can't access file outside of playground." - return func(*args, **kwargs) - - return wrapper - - """ write protocol: