36 lines
786 B
Python
36 lines
786 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from starlette.middleware.cors import CORSMiddleware
|
|
from starlette.responses import StreamingResponse
|
|
|
|
from domain.base import init_domains
|
|
from modes.agent import QueryRequest
|
|
from services import query_bill_agent
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
init_domains()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title="Integrate Agent API", lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.post("/query/bill")
|
|
async def query_agent(query: QueryRequest):
|
|
"""流式对话"""
|
|
return StreamingResponse(
|
|
query_bill_agent(query),
|
|
media_type="text/event-stream"
|
|
)
|