refactor starlette as API, langgraph from openrouter
This commit is contained in:
parent
1dec5d49ec
commit
4527ed19cc
7 changed files with 450 additions and 170 deletions
29
app.py
Normal file
29
app.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue