from starlette.applications import Starlette from starlette.routing import Route from controllers import create_chat, post_message, chat_stream, history from starlette.middleware import Middleware from starlette.middleware.cors import CORSMiddleware middleware = [ Middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) ] routes = [ Route("/chats", create_chat, methods=["POST"]), Route("/chats/{chat_id:str}", history, methods=["GET"]), Route("/chats/{chat_id:str}/messages", post_message, methods=["POST"]), Route("/chats/{chat_id:str}/stream", chat_stream, methods=["GET"]), ] application = Starlette(debug=True, routes=routes, middleware=middleware) # ----------------- Run ----------------- if __name__ == "__main__": import uvicorn uvicorn.run("app:application", host="0.0.0.0", port=8000, reload=True)