mirror of
https://github.com/maglore9900/max_headroom.git
synced 2025-06-06 03:25:34 +00:00
fixed timer
This commit is contained in:
parent
90e581eb0e
commit
d70de29052
2
main.py
2
main.py
@ -9,7 +9,7 @@ while True:
|
|||||||
text = graph.spk.listen()
|
text = graph.spk.listen()
|
||||||
# if text:
|
# if text:
|
||||||
# print(f"User: {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():
|
if "exit" in text.lower():
|
||||||
break
|
break
|
||||||
print("agent invoked")
|
print("agent invoked")
|
||||||
|
@ -109,8 +109,13 @@ class Agent:
|
|||||||
@tool("set_timer")
|
@tool("set_timer")
|
||||||
async def set_timer(self, time: str):
|
async def set_timer(self, time: str):
|
||||||
"""Sets a timer for the user
|
"""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.
|
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 ""
|
return ""
|
||||||
|
|
||||||
@ -148,20 +153,15 @@ class Agent:
|
|||||||
|
|
||||||
async def timer_tool(self, state: str):
|
async def timer_tool(self, state: str):
|
||||||
try:
|
try:
|
||||||
print("> spotify_tool")
|
print("> timer")
|
||||||
print(f"state: {state}")
|
print(f"state: {state}")
|
||||||
tool_action = state['agent_out'][0]
|
tool_action = state['agent_out'][0]
|
||||||
command = (lambda x: x.get('command') or x.get('self'))(tool_action.tool_input)
|
command = (lambda x: x.get('time') or x.get('self'))(tool_action.tool_input)
|
||||||
try:
|
if not command:
|
||||||
if not command:
|
raise ValueError("No valid command found in tool_input")
|
||||||
raise ValueError("No valid command found in tool_input")
|
subprocess.run(["python", "modules/timer.py", str(command)], shell=True)
|
||||||
subprocess.run(["python", "timer.py", command])
|
except subprocess.CalledProcessError as e:
|
||||||
# process = subprocess.Popen(["python", "modules/timer.py", command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
print(f"An error occurred: {e}")
|
||||||
except Exception as e:
|
|
||||||
print(f"An error occurred with timer: {e}")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"An error occurred: {e}")
|
|
||||||
|
|
||||||
async def run_query_agent(self, state: list):
|
async def run_query_agent(self, state: list):
|
||||||
print("> run_query_agent")
|
print("> run_query_agent")
|
||||||
@ -296,8 +296,8 @@ class Agent:
|
|||||||
answer = agent_out
|
answer = agent_out
|
||||||
|
|
||||||
print(f"answer: {answer}")
|
print(f"answer: {answer}")
|
||||||
if "ToolAgentAction" not in str(agent_out):
|
# if "ToolAgentAction" not in str(agent_out):
|
||||||
return answer
|
# return answer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class Speak:
|
|||||||
audio_data += audio_chunk
|
audio_data += audio_chunk
|
||||||
|
|
||||||
# Capture ambient noise in the first 2 seconds
|
# 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
|
ambient_noise_data += audio_chunk
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -22,6 +22,7 @@ import argparse
|
|||||||
from plyer import notification
|
from plyer import notification
|
||||||
|
|
||||||
def start_timer(seconds):
|
def start_timer(seconds):
|
||||||
|
seconds = int(seconds) # Convert to integer
|
||||||
print(f"Timer started for {seconds} seconds...")
|
print(f"Timer started for {seconds} seconds...")
|
||||||
time.sleep(seconds) # Sleep for the desired time
|
time.sleep(seconds) # Sleep for the desired time
|
||||||
notification.notify(
|
notification.notify(
|
||||||
|
@ -14,6 +14,7 @@ import time
|
|||||||
from plyer import notification
|
from plyer import notification
|
||||||
|
|
||||||
def start_timer(seconds):
|
def start_timer(seconds):
|
||||||
|
seconds = int(seconds) # Convert to integer
|
||||||
print(f"Timer started for {seconds} seconds...")
|
print(f"Timer started for {seconds} seconds...")
|
||||||
time.sleep(seconds) # Sleep for the desired time
|
time.sleep(seconds) # Sleep for the desired time
|
||||||
notification.notify(
|
notification.notify(
|
||||||
@ -23,4 +24,4 @@ def start_timer(seconds):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Example: Set a timer for 60 seconds
|
# Example: Set a timer for 60 seconds
|
||||||
start_timer(5)
|
# start_timer(5)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user