Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask user command #23

Merged
merged 5 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions loopgpt/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
DeleteAgent,
ListAgents,
)
from loopgpt.tools.user_manager import AskUser
from loopgpt.tools.base_tool import BaseTool
from loopgpt.tools.browser import Browser
from loopgpt.tools.code import ExecutePythonFile, ReviewCode, ImproveCode, WriteTests
Expand Down Expand Up @@ -55,4 +56,6 @@ def builtin_tools():
WriteTests,
ExecutePythonFile,
EvaluateMath,
AskUser,
Shell,
]
10 changes: 5 additions & 5 deletions loopgpt/tools/agent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from uuid import uuid4


class _AgentMangerTool(BaseTool):
class _AgentManagerTool(BaseTool):
pass


class CreateAgent(_AgentMangerTool):
class CreateAgent(_AgentManagerTool):
@property
def args(self):
return {
Expand Down Expand Up @@ -36,7 +36,7 @@ def run(self, name="", task="", prompt=""):
return {"uuid": id, "resp": resp}


class MessageAgent(_AgentMangerTool):
class MessageAgent(_AgentManagerTool):
@property
def args(self):
return {
Expand All @@ -55,7 +55,7 @@ def run(self, id, message):
return {"resp": resp}


class DeleteAgent(_AgentMangerTool):
class DeleteAgent(_AgentManagerTool):
@property
def args(self):
return {"id": "Agent id"}
Expand All @@ -72,7 +72,7 @@ def run(self, id):
return {f"resp": "Specified agent (id={id} not found.)"}


class ListAgents(_AgentMangerTool):
class ListAgents(_AgentManagerTool):
@property
def args(self):
return {}
Expand Down
2 changes: 1 addition & 1 deletion loopgpt/tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Shell(BaseTool):
@property
def desc(self):
return "Command line shell. (Non interactive commands only)"
return "Use this command to execute any terminal commands. (Non interactive commands only)"

@property
def args(self):
Expand Down
24 changes: 24 additions & 0 deletions loopgpt/tools/user_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from loopgpt.tools.base_tool import BaseTool
from loopgpt.utils.spinner import hide_spinner


class _UserManagerTool(BaseTool):
pass


class AskUser(_UserManagerTool):
@property
def args(self):
return {"message": "The question for the user."}

@property
def resp(self):
return {"response": "The response from the user."}

@property
def desc(self):
return "Use this command to get input from the user."

@hide_spinner
def run(self, message):
return {"response": input(f"{message}: ")}
14 changes: 14 additions & 0 deletions loopgpt/utils/spinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,17 @@ def inner(*args, **kwargs):
return func(*args, **kwargs)

return inner


def hide_spinner(func):
@wraps(func)
def inner(*args, **kwargs):
if ACTIVE_SPINNER:
ACTIVE_SPINNER.hide()
try:
return func(*args, **kwargs)
finally:
if ACTIVE_SPINNER:
ACTIVE_SPINNER.show()

return inner