chatsbt/app.py
2025-07-31 15:59:19 -04:00

31 lines
1,013 B
Python

from starlette.applications import Starlette
from starlette.routing import Route
from controllers import create_chat, post_message, chat_stream, history, get_models
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("/models", get_models, methods=["GET"]),
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)