Use post request for schedule function
This commit is contained in:
parent
9fa3ef5302
commit
eb07ca893e
|
@ -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.kernel import put_kernel_messages_into_queue
|
||||||
from ..server.utils.get_system_info import get_system_info
|
from ..server.utils.get_system_info import get_system_info
|
||||||
from ..server.stt.stt import stt_wav
|
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 setup_logging
|
||||||
from ..server.utils.logs import logger
|
from ..server.utils.logs import logger
|
||||||
|
@ -184,6 +184,7 @@ class Device:
|
||||||
if os.getenv('STT_RUNNER') == "client":
|
if os.getenv('STT_RUNNER') == "client":
|
||||||
# Run stt then send text
|
# Run stt then send text
|
||||||
text = stt_wav(wav_path)
|
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", "content": text})
|
||||||
send_queue.put({"role": "user", "type": "message", "end": True})
|
send_queue.put({"role": "user", "type": "message", "end": True})
|
||||||
else:
|
else:
|
||||||
|
@ -295,8 +296,6 @@ class Device:
|
||||||
code = message["content"]
|
code = message["content"]
|
||||||
result = interpreter.computer.run(language, code)
|
result = interpreter.computer.run(language, code)
|
||||||
send_queue.put(result)
|
send_queue.put(result)
|
||||||
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
logger.debug(traceback.format_exc())
|
logger.debug(traceback.format_exc())
|
||||||
logger.info(f"Connecting to `{WS_URL}`...")
|
logger.info(f"Connecting to `{WS_URL}`...")
|
||||||
|
|
|
@ -7,7 +7,7 @@ import queue
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
import re
|
import re
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI, Request
|
||||||
from fastapi.responses import PlainTextResponse
|
from fastapi.responses import PlainTextResponse
|
||||||
from starlette.websockets import WebSocket, WebSocketDisconnect
|
from starlette.websockets import WebSocket, WebSocketDisconnect
|
||||||
from .stt.stt import stt_bytes
|
from .stt.stt import stt_bytes
|
||||||
|
@ -107,6 +107,19 @@ async def websocket_endpoint(websocket: WebSocket):
|
||||||
logger.debug(traceback.format_exc())
|
logger.debug(traceback.format_exc())
|
||||||
logger.info(f"Connection lost. Error: {e}")
|
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):
|
async def receive_messages(websocket: WebSocket):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -2,26 +2,33 @@ import threading
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
def _add_message_to_queue(message):
|
def send_request(message) -> None:
|
||||||
# Define the message data and convert it to JSON
|
url = "http://localhost:8000/"
|
||||||
message_json = json.dumps({
|
data = {"text": message}
|
||||||
"role": "computer",
|
try:
|
||||||
"type": "console",
|
response = requests.post(url, json=data)
|
||||||
"format": "output",
|
response.raise_for_status()
|
||||||
"content": message
|
except requests.RequestException as e:
|
||||||
})
|
print(f"Request failed: {e}")
|
||||||
subprocess.run(['logger', '{TO_INTERPRETER{' + message_json + '}TO_INTERPRETER}'])
|
|
||||||
|
|
||||||
|
def schedule(days=0, hours=0, mins=0, secs=0, target_datetime=None, message="") -> None:
|
||||||
def schedule(dt: datetime, message: str) -> 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."""
|
||||||
""""Schedules a reminder at a specific time. At the specified time, the message will be added to the queue."""
|
|
||||||
# Calculate the delay in seconds
|
if target_datetime is None:
|
||||||
delay = (dt - datetime.now()).total_seconds()
|
# 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
|
# Create a timer
|
||||||
timer = threading.Timer(delay, _add_message_to_queue, args=[message])
|
timer = threading.Timer(delay, send_request, args=[message])
|
||||||
|
|
||||||
# Start the timer
|
# 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.
|
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 `datetime_object`.
|
||||||
|
|
||||||
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.
|
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.
|
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 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.
|
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.
|
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.
|
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 subprocess
|
||||||
import sys
|
import sys
|
||||||
import psutil
|
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():
|
def main():
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue