Skip to content

Commit

Permalink
remove default context, add q to quit stepped loop
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Jul 28, 2023
1 parent 7cbfe5d commit 61c4fc0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
3 changes: 1 addition & 2 deletions agentloop/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from .loop import start, step, stop, loop
from .input import step_with_input_key
from .context import create_default_context, create_context_builders
from .context import create_context_builders

__all__ = [
"start",
"stop",
"step",
"loop",
"step_with_input_key",
"create_default_context",
"create_context_builders",
]
19 changes: 0 additions & 19 deletions agentloop/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,3 @@ def build_context(context={}):
return context

return build_context


def create_default_context(context={}):
"""
Create a default context object
Args:
context: the last context made by the loop. Defaults to None.
Returns:
context: a dictionary containing the current context
"""
if context is None:
context = {}
context["current_time"] = datetime.now().strftime("%H:%M")
context["current_date"] = datetime.now().strftime("%Y-%m-%d")
context["platform"] = sys.platform
context["cwd"] = os.getcwd()
return context
16 changes: 12 additions & 4 deletions agentloop/input.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
def step_with_input_key(loop_data, input_key=None):
from .loop import stop

def step_with_input_key(loop_data):
"""
Listen for a specified key press, and when detected, step the loop
Expand All @@ -19,11 +21,17 @@ def step_with_input_key(loop_data, input_key=None):
"pynput not installed. Please install it with `pip install pynput`"
)

if input_key is None:
input_key = keyboard.Key.space
input_key = keyboard.Key.space

quit_key = "q"

def on_press(key):
if key == input_key:
# check if key includes the quit key
if hasattr(key, "char") and key.char == quit_key:
print("Quitting...")
stop(loop_data)
elif key == input_key:
print("Stepping...")
loop_data["step_event"].set()

listener = None
Expand Down

0 comments on commit 61c4fc0

Please sign in to comment.