Saltar al contenido principal

馃殌Servidor FastAPI de Ejemplo

La actualizaci贸n del generador habilita que Open Interpreter sea controlado a trav茅s de endpoints HTTP REST:

# server.py

from fastapi import FastAPI
from fastapi.responses import StreamingResponse
from interpreter import interpreter

app = FastAPI()

@app.get("/chat")
def chat_endpoint(message: str):
def event_stream():
for result in interpreter.chat(message, stream=True):
yield f"data: {result}\n\n"

return StreamingResponse(event_stream(), media_type="text/event-stream")

@app.get("/history")
def history_endpoint():
return interpreter.messages
pip install fastapi uvicorn
uvicorn server:app --reload

Tambi茅n puedes iniciar un servidor id茅ntico al anterior simplemente ejecutando interpreter.server().