Open Interpreter FastAPI

parmarjatin4911@gmail.com - Jan 28 - - Dev Community

**

Open Interpreter FastAPI**

Streaming

from fastapi import FastAPI
from fastapi.responses import StreamingResponse
from interpreter import interpreter
interpreter.auto_run = True
interpreter.llm.model: "gpt-4-1106-preview"

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")
Enter fullscreen mode Exit fullscreen mode

@app.get("/history")
def history_endpoint():
return interpreter.messages

Note: stream=False to stop streaming.
Run

export OPENAI_API_KEY=st-xxxxxxxxxxxxxxxxxxx
pip install fastapi uvicorn
uvicorn server:app --reload

Test

curl http://localhost:8000/chat\?message\=list+files+in+desktop

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player