From 036ee268dd6043c88f665e11fdc73b5c3932f99e Mon Sep 17 00:00:00 2001 From: killian <63927363+KillianLucas@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:39:57 -0800 Subject: [PATCH] Queue --- OS/01/core/interpreter/main.py | 34 +++++++++++++++++++++++++++++++++ OS/01/core/interpreter/start.py | 4 +++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/OS/01/core/interpreter/main.py b/OS/01/core/interpreter/main.py index 1d38cc1..ff509c2 100644 --- a/OS/01/core/interpreter/main.py +++ b/OS/01/core/interpreter/main.py @@ -10,6 +10,30 @@ import uvicorn from fastapi import FastAPI, WebSocket import asyncio import json +import os +import glob + +def check_queue(): + queue_files = glob.glob("/queue/*.json") + if queue_files: + with open(queue_files[0], 'r') as file: + data = json.load(file) + os.remove(queue_files[0]) + return data + else: + return None + +def save_conversation(messages): + with open('/conversations/user.json', 'w') as file: + json.dump(messages, file) + +def load_conversation(): + try: + with open('/conversations/user.json', 'r') as file: + messages = json.load(file) + return messages + except FileNotFoundError: + return [] def main(interpreter): @@ -36,9 +60,16 @@ def main(interpreter): for response in interpreter.chat( message=data, stream=True, display=False ): + # Check queue + queued_message = check_queue() + if queued_message: + data = queued_message + break + if task.done(): data = task.result() # Get the new message break # Break the loop and start processing the new message + # Send out assistant message chunks if ( response.get("type") == "message" @@ -47,6 +78,8 @@ def main(interpreter): ): await websocket.send_text(response["content"]) await asyncio.sleep(0.01) # Add a small delay + + # If it just finished sending an assistant message, send a newline. Otherwise it looks weird. if ( response.get("type") == "message" and response["role"] == "assistant" @@ -54,6 +87,7 @@ def main(interpreter): ): await websocket.send_text("\n") await asyncio.sleep(0.01) # Add a small delay + if not task.done(): data = ( await task diff --git a/OS/01/core/interpreter/start.py b/OS/01/core/interpreter/start.py index c4470bc..5e11c32 100644 --- a/OS/01/core/interpreter/start.py +++ b/OS/01/core/interpreter/start.py @@ -39,6 +39,8 @@ To do this, schedule a reminder based on estimated completion time using `comput 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. +Remember: You can run Python code. + """.strip() interpreter.system_message = system_message @@ -61,7 +63,7 @@ for file in glob.glob('/tools/*.py'): # Hosted settings interpreter.llm.api_key = os.getenv('OPENAI_API_KEY') -interpreter.llm.model = "gpt-3.5-turbo" +interpreter.llm.model = "gpt-4" ### MISC SETTINGS