pull/3/head
killian 12 months ago
parent 5f22885e75
commit 036ee268dd

@ -10,6 +10,30 @@ import uvicorn
from fastapi import FastAPI, WebSocket from fastapi import FastAPI, WebSocket
import asyncio import asyncio
import json 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): def main(interpreter):
@ -36,9 +60,16 @@ def main(interpreter):
for response in interpreter.chat( for response in interpreter.chat(
message=data, stream=True, display=False message=data, stream=True, display=False
): ):
# Check queue
queued_message = check_queue()
if queued_message:
data = queued_message
break
if task.done(): if task.done():
data = task.result() # Get the new message data = task.result() # Get the new message
break # Break the loop and start processing the new message break # Break the loop and start processing the new message
# Send out assistant message chunks # Send out assistant message chunks
if ( if (
response.get("type") == "message" response.get("type") == "message"
@ -47,6 +78,8 @@ def main(interpreter):
): ):
await websocket.send_text(response["content"]) await websocket.send_text(response["content"])
await asyncio.sleep(0.01) # Add a small delay 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 ( if (
response.get("type") == "message" response.get("type") == "message"
and response["role"] == "assistant" and response["role"] == "assistant"
@ -54,6 +87,7 @@ def main(interpreter):
): ):
await websocket.send_text("\n") await websocket.send_text("\n")
await asyncio.sleep(0.01) # Add a small delay await asyncio.sleep(0.01) # Add a small delay
if not task.done(): if not task.done():
data = ( data = (
await task await task

@ -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. 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() """.strip()
interpreter.system_message = system_message interpreter.system_message = system_message
@ -61,7 +63,7 @@ for file in glob.glob('/tools/*.py'):
# Hosted settings # Hosted settings
interpreter.llm.api_key = os.getenv('OPENAI_API_KEY') interpreter.llm.api_key = os.getenv('OPENAI_API_KEY')
interpreter.llm.model = "gpt-3.5-turbo" interpreter.llm.model = "gpt-4"
### MISC SETTINGS ### MISC SETTINGS

Loading…
Cancel
Save