diff --git a/01OS/01OS/clients/base_device.py b/01OS/01OS/clients/base_device.py index 42aa60c..0ba3024 100644 --- a/01OS/01OS/clients/base_device.py +++ b/01OS/01OS/clients/base_device.py @@ -29,7 +29,7 @@ from interpreter import interpreter # Just for code execution. Maybe we should l from ..server.utils.kernel import put_kernel_messages_into_queue from ..server.utils.get_system_info import get_system_info from ..server.stt.stt import stt_wav -from process_utils import kill_process_tree +from ..server.utils.process_utils import kill_process_tree from ..server.utils.logs import setup_logging from ..server.utils.logs import logger @@ -184,6 +184,7 @@ class Device: if os.getenv('STT_RUNNER') == "client": # Run stt then send text text = stt_wav(wav_path) + logger.debug(f"STT result: {text}") send_queue.put({"role": "user", "type": "message", "content": text}) send_queue.put({"role": "user", "type": "message", "end": True}) else: @@ -295,8 +296,6 @@ class Device: code = message["content"] result = interpreter.computer.run(language, code) send_queue.put(result) - - except: logger.debug(traceback.format_exc()) logger.info(f"Connecting to `{WS_URL}`...") diff --git a/01OS/01OS/server/server.py b/01OS/01OS/server/server.py index 1a55f9a..c132b8a 100644 --- a/01OS/01OS/server/server.py +++ b/01OS/01OS/server/server.py @@ -7,7 +7,7 @@ import queue import os import traceback import re -from fastapi import FastAPI +from fastapi import FastAPI, Request from fastapi.responses import PlainTextResponse from starlette.websockets import WebSocket, WebSocketDisconnect from .stt.stt import stt_bytes @@ -107,6 +107,19 @@ async def websocket_endpoint(websocket: WebSocket): logger.debug(traceback.format_exc()) logger.info(f"Connection lost. Error: {e}") + +@app.post("/") +async def add_computer_message(request: Request): + body = await request.json() + text = body.get("text") + if not text: + return {"error": "Missing 'text' in request body"}, 422 + message = {"role": "computer", "type": "console", "format": "output", "content": text} + from_computer.put({"role": "computer", "type": "console", "format": "output", "start": True}) + from_computer.put(message) + from_computer.put({"role": "computer", "type": "console", "format": "output", "end": True}) + + async def receive_messages(websocket: WebSocket): while True: try: diff --git a/01OS/01OS/server/skills/schedule.py b/01OS/01OS/server/skills/schedule.py index 2292d42..e6c150c 100644 --- a/01OS/01OS/server/skills/schedule.py +++ b/01OS/01OS/server/skills/schedule.py @@ -2,26 +2,33 @@ import threading from datetime import datetime import json import subprocess +import requests -def _add_message_to_queue(message): - # Define the message data and convert it to JSON - message_json = json.dumps({ - "role": "computer", - "type": "console", - "format": "output", - "content": message - }) - subprocess.run(['logger', '{TO_INTERPRETER{' + message_json + '}TO_INTERPRETER}']) +def send_request(message) -> None: + url = "http://localhost:8000/" + data = {"text": message} + try: + response = requests.post(url, json=data) + response.raise_for_status() + except requests.RequestException as e: + print(f"Request failed: {e}") - -def schedule(dt: datetime, message: str) -> None: - """"Schedules a reminder at a specific time. At the specified time, the message will be added to the queue.""" - # Calculate the delay in seconds - delay = (dt - datetime.now()).total_seconds() +def schedule(days=0, hours=0, mins=0, secs=0, target_datetime=None, message="") -> None: + """Schedules a reminder after a specified delay or for a specific datetime. The delay is defined by days, hours, minutes, and seconds. If a target_datetime is provided, it schedules the reminder for that datetime instead.""" + + if target_datetime is None: + # Calculate the delay in seconds if no target_datetime is provided + delay = days * 86400 + hours * 3600 + mins * 60 + secs + else: + # Calculate the delay in seconds from now until the target datetime + now = datetime.now() + delay = (target_datetime - now).total_seconds() + # Ensure delay is non-negative + delay = max(0, delay) # Create a timer - timer = threading.Timer(delay, _add_message_to_queue, args=[message]) + timer = threading.Timer(delay, send_request, args=[message]) # Start the timer - timer.start() \ No newline at end of file + timer.start() \ No newline at end of file diff --git a/01OS/01OS/server/system_messages/BaseSystemMessage.py b/01OS/01OS/server/system_messages/BaseSystemMessage.py index 5b30698..526d00a 100644 --- a/01OS/01OS/server/system_messages/BaseSystemMessage.py +++ b/01OS/01OS/server/system_messages/BaseSystemMessage.py @@ -45,7 +45,7 @@ When the user tells you about a set of tasks, you should intelligently order tas After starting a task, you should check in with the user around the estimated completion time to see if the task is completed. -To do this, schedule a reminder based on estimated completion time using the function `schedule(datetime_object, "Your message here.")`, WHICH HAS ALREADY BEEN IMPORTED. YOU DON'T NEED TO IMPORT THE `schedule` FUNCTION. IT IS AVALIABLE. You'll recieve the message at `datetime_object`. +To do this, schedule a reminder based on estimated completion time using the function `schedule(days=0, hours=0, mins=0, secs=0, datetime="valid date time", message="Your message here.")`, WHICH HAS ALREADY BEEN IMPORTED. YOU DON'T NEED TO IMPORT THE `schedule` FUNCTION. IT IS AVAILABLE. You'll receive the message at the time you scheduled it. You guide the user through the list one task at a time, convincing them to move forward, giving a pep talk if need be. Your job is essentially to answer "what should I (the user) be doing right now?" for every moment of the day. @@ -71,7 +71,7 @@ You are the 01, an executive assistant that can complete **any** task. When you execute code, it will be executed **on the user's machine**. The user has given you **full and complete permission** to execute any code necessary to complete the task. Execute the code. You can access the internet. Run **any code** to achieve the goal, and if at first you don't succeed, try again and again. You can install new packages. -Be concise. Your messages are being read aloud to the user. DO NOT MAKE PLANS. Immediatly run code. +Be concise. Your messages are being read aloud to the user. DO NOT MAKE PLANS. Immediately run code. Try to spread complex tasks over multiple code blocks. Manually summarize text. You cannot use other libraries to do this. You MUST MANUALLY SUMMARIZE, WITHOUT CODING. diff --git a/01OS/process_utils.py b/01OS/01OS/server/utils/process_utils.py similarity index 100% rename from 01OS/process_utils.py rename to 01OS/01OS/server/utils/process_utils.py diff --git a/01OS/start.py b/01OS/start.py index be75a75..b9d2f34 100644 --- a/01OS/start.py +++ b/01OS/start.py @@ -7,7 +7,10 @@ import os import subprocess import sys import psutil -from process_utils import kill_process_tree +import importlib +# Can't import normally because it starts with a number +process_utils = importlib.import_module("01OS.server.utils.process_utils") +kill_process_tree = process_utils.kill_process_tree def main():