使用FastAPI与进行SSE相应
前言:最近使用大模型的API时候都会用到SSE响应,目的是模型生成一点东西,返回一点东西。下面记录一下Python的使用方法。
1. 回顾一下用FastAPI写一个最简单的接口
from fastapi import FastAPI, Request
import uvicorn
app = FastAPI()
@app.get("/")
async def root():
return {
"message": "Hello World"}
if __name__ == "__main__":
uvicorn.run(app, host='0.0.0.0', port=6006)