基础FastAPI服务
·
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
import aiohttp
import asyncio
import uvicorn
import os
import sys
import time
import json
from llm import get_text_nostream
# ===================== 初始化 全局变量 =====================
app = FastAPI()
with open("urgeVaccineStrategy.md", "r", encoding="utf-8") as f:
system_prompt = f.read()
SYSTEM_PROMPT = system_prompt
THINKING = False
# ===================== API接口 =====================
@app.post("/cuizong")
async def cuizong(request: Request):
data = await request.json()
prompt = str(data)
str_response = get_text_nostream(prompt, thinking=THINKING, system_prompt=SYSTEM_PROMPT)
json_response = json.loads(str_response)
response_json = {
"result": json_response.get('result', ''),
"nextNoticeTime": json_response.get('nextNoticeTime', ''),
"strategy": json_response.get('strategy', '')
}
tmp = {"data": response_json}
return JSONResponse(content=tmp)
if __name__ == '__main__':
uvicorn.run(
"main:app",
host="0.0.0.0",
port=10997)
更多推荐
所有评论(0)