2025-07-21 18:15:51 -04:00
|
|
|
from starlette.applications import Starlette
|
|
|
|
|
from starlette.routing import Route
|
2025-07-31 15:59:19 -04:00
|
|
|
from controllers import create_chat, post_message, chat_stream, history, get_models
|
2025-07-21 18:15:51 -04:00
|
|
|
from starlette.middleware import Middleware
|
|
|
|
|
from starlette.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
|
|
|
middleware = [
|
|
|
|
|
Middleware(
|
|
|
|
|
CORSMiddleware,
|
2025-07-29 23:42:15 -04:00
|
|
|
allow_origins=["*"],
|
2025-07-21 18:15:51 -04:00
|
|
|
allow_credentials=True,
|
|
|
|
|
allow_methods=["*"],
|
|
|
|
|
allow_headers=["*"],
|
|
|
|
|
)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
routes = [
|
2025-07-31 15:59:19 -04:00
|
|
|
Route("/models", get_models, methods=["GET"]),
|
2025-07-21 18:15:51 -04:00
|
|
|
Route("/chats", create_chat, methods=["POST"]),
|
2025-07-29 23:42:15 -04:00
|
|
|
Route("/chats/{chat_id:str}", history, methods=["GET"]),
|
2025-07-21 18:15:51 -04:00
|
|
|
Route("/chats/{chat_id:str}/messages", post_message, methods=["POST"]),
|
2025-07-29 23:42:15 -04:00
|
|
|
Route("/chats/{chat_id:str}/stream", chat_stream, methods=["GET"]),
|
2025-07-21 18:15:51 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
application = Starlette(debug=True, routes=routes, middleware=middleware)
|
|
|
|
|
|
|
|
|
|
# ----------------- Run -----------------
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
import uvicorn
|
2025-07-29 23:42:15 -04:00
|
|
|
uvicorn.run("app:application", host="0.0.0.0", port=8000, reload=True)
|