parent
d0857f7170
commit
777ab42f75
@ -1 +1 @@
|
|||||||
[{"role": "user", "type": "message", "content": "Hi.\n"}]
|
[{"role": "user", "type": "message", "content": "Hi, can you hear me?\n"}]
|
@ -1,17 +0,0 @@
|
|||||||
from .check_filtered_kernel import check_filtered_kernel
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
async def put_kernel_messages_into_queue(queue):
|
|
||||||
while True:
|
|
||||||
text = check_filtered_kernel()
|
|
||||||
if text:
|
|
||||||
if isinstance(queue, asyncio.Queue):
|
|
||||||
await queue.put({"role": "computer", "type": "console", "start": True})
|
|
||||||
await queue.put({"role": "computer", "type": "console", "format": "output", "content": text})
|
|
||||||
await queue.put({"role": "computer", "type": "console", "end": True})
|
|
||||||
else:
|
|
||||||
queue.put({"role": "computer", "type": "console", "start": True})
|
|
||||||
queue.put({"role": "computer", "type": "console", "format": "output", "content": text})
|
|
||||||
queue.put({"role": "computer", "type": "console", "end": True})
|
|
||||||
|
|
||||||
await asyncio.sleep(5)
|
|
@ -1,28 +0,0 @@
|
|||||||
"""
|
|
||||||
Exposes a SSE streaming server endpoint at /run, which recieves language and code,
|
|
||||||
and streams the output.
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
from interpreter import interpreter
|
|
||||||
import uvicorn
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from fastapi.responses import StreamingResponse
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
class Code(BaseModel):
|
|
||||||
language: str
|
|
||||||
code: str
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
@app.post("/run")
|
|
||||||
async def run_code(code: Code):
|
|
||||||
def generator():
|
|
||||||
for chunk in interpreter.computer.run(code.language, code.code):
|
|
||||||
yield json.dumps(chunk)
|
|
||||||
return StreamingResponse(generator())
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv('COMPUTER_PORT', 9000)))
|
|
Loading…
Reference in new issue