langchain tools

Former-commit-id: 68916a97aa
pull/47/head
Kye 1 year ago
parent c3bced2280
commit ad3e0fbd84

@ -18,9 +18,9 @@ from ptrace.debugger import (
) )
from ptrace.func_call import FunctionCallOptions from ptrace.func_call import FunctionCallOptions
from ptrace.syscall import PtraceSyscall from ptrace.syscall import PtraceSyscall
from ptrace.Tools import signal_to_exitcode from ptrace.tools import signal_to_exitcode
from swarms.agents.Tools.base import BaseToolSet, SessionGetter, ToolScope, Tool from swarms.agents.tools.base import BaseToolSet, SessionGetter, ToolScope, tool
from swarms.utils.logger import logger from swarms.utils.logger import logger
from swarms.utils.main import ANSI, Color, Style # test from swarms.utils.main import ANSI, Color, Style # test
@ -34,7 +34,7 @@ def verify(func):
try: try:
filepath = args[0].filepath filepath = args[0].filepath
except AttributeError: except AttributeError:
raise Exception("This Tool doesn't have filepath. Please check your code.") raise Exception("This tool doesn't have filepath. Please check your code.")
if not str(Path(filepath).resolve()).startswith(str(Path().resolve())): if not str(Path(filepath).resolve()).startswith(str(Path().resolve())):
return "You can't access file outside of playground." return "You can't access file outside of playground."
return func(*args, **kwargs) return func(*args, **kwargs)
@ -201,7 +201,7 @@ class Terminal(BaseToolSet):
def __init__(self): def __init__(self):
self.sessions: Dict[str, List[SyscallTracer]] = {} self.sessions: Dict[str, List[SyscallTracer]] = {}
@Tool( @tool(
name="Terminal", name="Terminal",
description="Executes commands in a terminal." description="Executes commands in a terminal."
"If linux errno occurs, we have to solve the problem with the terminal. " "If linux errno occurs, we have to solve the problem with the terminal. "
@ -629,7 +629,7 @@ class CodePatcher:
class CodeEditor(BaseToolSet): class CodeEditor(BaseToolSet):
@Tool( @tool(
name="CodeEditor.READ", name="CodeEditor.READ",
description="Read and understand code. " description="Read and understand code. "
"Input should be filename and line number group. ex. test.py|1-10 " "Input should be filename and line number group. ex. test.py|1-10 "
@ -647,7 +647,7 @@ class CodeEditor(BaseToolSet):
) )
return output return output
@Tool( @tool(
name="CodeEditor.SUMMARY", name="CodeEditor.SUMMARY",
description="Summary code. " description="Summary code. "
"Read the code structured into a tree. " "Read the code structured into a tree. "
@ -667,10 +667,10 @@ class CodeEditor(BaseToolSet):
) )
return output return output
@Tool( @tool(
name="CodeEditor.APPEND", name="CodeEditor.APPEND",
description="Append code to the existing file. " description="Append code to the existing file. "
"If the code is completed, use the Terminal Tool to execute it, if not, append the code through the this Tool. " "If the code is completed, use the Terminal tool to execute it, if not, append the code through the this tool. "
"Input should be filename and code to append. " "Input should be filename and code to append. "
"Input code must be the code that should be appended, NOT whole code. " "Input code must be the code that should be appended, NOT whole code. "
"ex. test.py\nprint('hello world')\n " "ex. test.py\nprint('hello world')\n "
@ -689,10 +689,10 @@ class CodeEditor(BaseToolSet):
) )
return output return output
@Tool( @tool(
name="CodeEditor.WRITE", name="CodeEditor.WRITE",
description="Write code to create a new Tool. " description="Write code to create a new tool. "
"If the code is completed, use the Terminal Tool to execute it, if not, append the code through the CodeEditor.APPEND Tool. " "If the code is completed, use the Terminal tool to execute it, if not, append the code through the CodeEditor.APPEND tool. "
"Input should be formatted like: " "Input should be formatted like: "
"<filename>\n<code>\n\n" "<filename>\n<code>\n\n"
"Here is an example: " "Here is an example: "
@ -712,7 +712,7 @@ class CodeEditor(BaseToolSet):
) )
return output return output
@Tool( @tool(
name="CodeEditor.PATCH", name="CodeEditor.PATCH",
description="Patch the code to correct the error if an error occurs or to improve it. " description="Patch the code to correct the error if an error occurs or to improve it. "
"Input is a list of patches. The patch is separated by {seperator}. ".format( "Input is a list of patches. The patch is separated by {seperator}. ".format(
@ -742,7 +742,7 @@ class CodeEditor(BaseToolSet):
) )
return output return output
@Tool( @tool(
name="CodeEditor.DELETE", name="CodeEditor.DELETE",
description="Delete code in file for a new start. " description="Delete code in file for a new start. "
"Input should be filename." "Input should be filename."

@ -1,14 +1,16 @@
from swarms.agents.tools.base import BaseToolSet, SessionGetter, ToolScope, Tool from langchain.tools import tool
from swarms.agents.tools.base import BaseToolSet, SessionGetter, ToolScope
from swarms.utils.logger import logger from swarms.utils.logger import logger
class ExitConversation(BaseToolSet): class ExitConversation(BaseToolSet):
@Tool( @tool(
name="Exit Conversation", name="Exit Conversation",
description="A tool to exit the conversation. " description="A tool to exit the conversation. "
"Use this when you want to exit the conversation. " "Use this when you want to exit the conversation. "
"The input should be a message that the conversation is over.", "The input should be a message that the conversation is over.",
# scope=ToolScope.SESSION, scope=ToolScope.SESSION,
) )
def exit(self, message: str, get_session: SessionGetter) -> str: def exit(self, message: str, get_session: SessionGetter) -> str:
"""Run the tool.""" """Run the tool."""

Loading…
Cancel
Save