Merge pull request #64 from tyfiero/Schedule-function-functionality
Schedule function functionality
This commit is contained in:
commit
ed1fd91087
|
@ -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}`...")
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
timer.start()
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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():
|
||||
|
||||
|
|
Loading…
Reference in New Issue