feat: 测试同步异步阻塞的接口
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from langchain.chat_models import init_chat_model
|
from langchain.chat_models import init_chat_model
|
||||||
from langserve import add_routes
|
from langserve import add_routes
|
||||||
@@ -34,3 +38,22 @@ def add_test_route(app: FastAPI):
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_routes(app=app, runnable=model, path="/doubao")
|
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"}
|
||||||
|
|||||||
Reference in New Issue
Block a user