From d70de290528ee966397bb26329de2632998e08fd Mon Sep 17 00:00:00 2001 From: maglore9900 Date: Fri, 13 Sep 2024 23:26:41 -0400 Subject: [PATCH] fixed timer --- main.py | 2 +- modules/agent.py | 30 +++++++++++++++--------------- modules/speak.py | 2 +- modules/timer.py | 1 + modules/timer_test.py | 3 ++- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/main.py b/main.py index 2f68218..49d0e50 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ while True: text = graph.spk.listen() # if text: # print(f"User: {text}") - if text and "hey" in text.lower() and "max" in text.lower() or text and "hey" in text.lower() and "mac" in text.lower(): + if text and "hey" in text.lower() and "max" in text.lower() or text and "hey" in text.lower() and "mac" in text.lower()or text and "amax" in text.lower(): if "exit" in text.lower(): break print("agent invoked") diff --git a/modules/agent.py b/modules/agent.py index b3bbb7b..6063569 100644 --- a/modules/agent.py +++ b/modules/agent.py @@ -109,8 +109,13 @@ class Agent: @tool("set_timer") async def set_timer(self, time: str): """Sets a timer for the user - convert the user provided time to seconds and then start the timer Use this tool when the user says 'set timer' or similar words in their query. + convert the user provided time to seconds + then pass the value in seconds as the time paramter. + Examples: + "set a timer for 5 minutes" results in 'time': 300 + "start a timer for 10 seconds" results in 'time': 10 + Only pass the numerical value of seconds to this tool!!! """ return "" @@ -148,20 +153,15 @@ class Agent: async def timer_tool(self, state: str): try: - print("> spotify_tool") + print("> timer") print(f"state: {state}") tool_action = state['agent_out'][0] - command = (lambda x: x.get('command') or x.get('self'))(tool_action.tool_input) - try: - if not command: - raise ValueError("No valid command found in tool_input") - subprocess.run(["python", "timer.py", command]) - # process = subprocess.Popen(["python", "modules/timer.py", command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) - except Exception as e: - print(f"An error occurred with timer: {e}") - - except Exception as e: - print(f"An error occurred: {e}") + command = (lambda x: x.get('time') or x.get('self'))(tool_action.tool_input) + if not command: + raise ValueError("No valid command found in tool_input") + subprocess.run(["python", "modules/timer.py", str(command)], shell=True) + except subprocess.CalledProcessError as e: + print(f"An error occurred: {e}") async def run_query_agent(self, state: list): print("> run_query_agent") @@ -296,8 +296,8 @@ class Agent: answer = agent_out print(f"answer: {answer}") - if "ToolAgentAction" not in str(agent_out): - return answer + # if "ToolAgentAction" not in str(agent_out): + # return answer diff --git a/modules/speak.py b/modules/speak.py index bfa484b..fb29d76 100644 --- a/modules/speak.py +++ b/modules/speak.py @@ -51,7 +51,7 @@ class Speak: audio_data += audio_chunk # Capture ambient noise in the first 2 seconds - if i < int(self.sample_rate / self.chunk_size * 2): # First 2 seconds + if i < int(self.sample_rate / self.chunk_size * 1): # First 1 seconds ambient_noise_data += audio_chunk finally: diff --git a/modules/timer.py b/modules/timer.py index 099ca59..195a3c5 100644 --- a/modules/timer.py +++ b/modules/timer.py @@ -22,6 +22,7 @@ import argparse from plyer import notification def start_timer(seconds): + seconds = int(seconds) # Convert to integer print(f"Timer started for {seconds} seconds...") time.sleep(seconds) # Sleep for the desired time notification.notify( diff --git a/modules/timer_test.py b/modules/timer_test.py index 96d5dd5..468e127 100644 --- a/modules/timer_test.py +++ b/modules/timer_test.py @@ -14,6 +14,7 @@ import time from plyer import notification def start_timer(seconds): + seconds = int(seconds) # Convert to integer print(f"Timer started for {seconds} seconds...") time.sleep(seconds) # Sleep for the desired time notification.notify( @@ -23,4 +24,4 @@ def start_timer(seconds): ) # Example: Set a timer for 60 seconds -start_timer(5) +# start_timer(5)