29 lines
No EOL
930 B
Python
29 lines
No EOL
930 B
Python
from starlette.applications import Starlette
|
|
from starlette.routing import Route
|
|
from controllers import create_chat, post_message, stream_response
|
|
from starlette.middleware import Middleware
|
|
from starlette.middleware.cors import CORSMiddleware
|
|
|
|
middleware = [
|
|
Middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # change to ["http://localhost:3000"] etc. in prod
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
]
|
|
|
|
routes = [
|
|
Route("/chats", create_chat, methods=["POST"]),
|
|
Route("/chats/{chat_id:str}/messages", post_message, methods=["POST"]),
|
|
Route("/chats/{chat_id:str}/stream", stream_response, methods=["GET"]),
|
|
]
|
|
|
|
|
|
application = Starlette(debug=True, routes=routes, middleware=middleware)
|
|
|
|
# ----------------- Run -----------------
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(application, host="0.0.0.0", port=8000) |