helpers organization in developers tools

Former-commit-id: f2d8dd30e2
pull/47/head
Kye 2 years ago
parent ab2acc7c37
commit 0d10bd1b9e

@ -30,6 +30,13 @@ _____________________________________
4. Use searchable names. 4. Use searchable names.
5. Replace magic numbers with named constants. 5. Replace magic numbers with named constants.
6. Avoid encodings. Don't append prefixes or type information. 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 ## Functions rules
1. Small. 1. Small.
@ -38,6 +45,18 @@ _____________________________________
4. Prefer fewer arguments. 4. Prefer fewer arguments.
5. Have no side effects. 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. 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 ## Comments rules
1. Always try to explain yourself in code. 1. Always try to explain yourself in code.

@ -7,7 +7,7 @@
#tools #tools
from swarms.agents.tools.base import BaseTool, Tool, StructuredTool, ToolWrapper, BaseToolSet, ToolCreator, GlobalToolsCreator, SessionToolsCreator, ToolsFactory 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.exit_conversation import ExitConversation
from swarms.agents.tools.models import MaskFormer, ImageEditing, InstructPix2Pix, Text2Image, VisualQuestionAnswering, ImageCaptioning from swarms.agents.tools.models import MaskFormer, ImageEditing, InstructPix2Pix, Text2Image, VisualQuestionAnswering, ImageCaptioning

@ -25,6 +25,24 @@ from swarms.utils.logger import logger
from swarms.utils.main import ANSI, Color, Style # test 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): class SyscallTimeoutException(Exception):
def __init__(self, pid: int, *args) -> None: def __init__(self, pid: int, *args) -> None:
super().__init__(f"deadline exceeded while waiting syscall for {pid}", *args) super().__init__(f"deadline exceeded while waiting syscall for {pid}", *args)
@ -114,7 +132,6 @@ class SyscallTracer:
return exitcode, reason return exitcode, reason
PipeType = Union[Literal["stdout"], Literal["stderr"]]
class StdoutTracer: 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: write protocol:

Loading…
Cancel
Save