mirror of
https://github.com/Canner/WrenAI.git
synced 2026-09-24 23:29:49 +08:00
chore(wren-ai-service): move the development purpose API to the development router (#381)
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import uvicorn
|
||||
@@ -36,7 +34,6 @@ async def lifespan(app: FastAPI):
|
||||
|
||||
app = FastAPI(lifespan=lifespan, redoc_url=None)
|
||||
|
||||
app.include_router(routers.router, prefix="/v1")
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
@@ -44,6 +41,11 @@ app.add_middleware(
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
app.include_router(routers.router, prefix="/v1")
|
||||
if os.getenv("ENV") == "dev":
|
||||
from src.web import development
|
||||
|
||||
app.include_router(development.router, prefix="/dev")
|
||||
|
||||
|
||||
@app.exception_handler(Exception)
|
||||
@@ -72,20 +74,6 @@ def health():
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
@app.get("/dummy")
|
||||
async def dummy(sleep: int = 4, is_async: bool = True, should_sleep: bool = True):
|
||||
"""
|
||||
Dummy endpoint to test async behavior by sleeping for several seconds
|
||||
"""
|
||||
if should_sleep:
|
||||
if is_async:
|
||||
await asyncio.sleep(sleep)
|
||||
else:
|
||||
time.sleep(sleep)
|
||||
|
||||
return {"status": "dummy"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
server_host = os.getenv("WREN_AI_SERVICE_HOST") or "127.0.0.1"
|
||||
server_port = (
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/dummy")
|
||||
async def dummy(sleep: int = 4, is_async: bool = True, should_sleep: bool = True):
|
||||
"""
|
||||
Dummy endpoint to test async behavior by sleeping for several seconds
|
||||
"""
|
||||
if should_sleep:
|
||||
if is_async:
|
||||
await asyncio.sleep(sleep)
|
||||
else:
|
||||
time.sleep(sleep)
|
||||
|
||||
return {"status": "dummy"}
|
||||
@@ -230,4 +230,4 @@ class AskDetailsUser(FastHttpUser):
|
||||
class DummyUser(FastHttpUser):
|
||||
@task
|
||||
def dummy(self):
|
||||
self.client.get(url="/dummy")
|
||||
self.client.get(url="/dev/dummy")
|
||||
|
||||
Reference in New Issue
Block a user