feat: 测试同步异步阻塞的接口

This commit is contained in:
martsforever
2026-04-01 14:22:52 +08:00
parent d2ee7c1d9b
commit eec980a3ca
+23
View File
@@ -1,3 +1,7 @@
import asyncio
import os
import time
from fastapi import FastAPI
from langchain.chat_models import init_chat_model
from langserve import add_routes
@@ -34,3 +38,22 @@ def add_test_route(app: FastAPI):
)
add_routes(app=app, runnable=model, path="/doubao")
@app.get("/test")
async def test():
print(f"Process {os.getpid()} handling /test")
return {"message": "Hello World"}
@app.get("/sync_delay")
async def sync_delay(delay: int = 1):
"""同步延迟delay秒"""
print(f"Process {os.getpid()} handling /sync_delay")
time.sleep(delay)
return {"hello": "world"}
@app.get("/async_delay")
async def async_delay(delay: int = 1):
"""异步延迟delay秒"""
print(f"Process {os.getpid()} handling /async_delay")
await asyncio.sleep(delay)
return {"hello": "world"}