2024-06-15 15:41:31 +08:00
|
|
|
|
from fastapi import FastAPI, BackgroundTasks
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
from typing import Literal, Optional
|
|
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
2024-06-19 10:05:10 +08:00
|
|
|
|
from insights import message_manager
|
2024-06-15 15:41:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Request(BaseModel):
|
|
|
|
|
"""
|
|
|
|
|
Input model
|
|
|
|
|
input = {'user_id': str, 'type': str, 'content':str, 'addition': Optional[str]}
|
|
|
|
|
Type is one of "text", "publicMsg", "site" and "url";
|
|
|
|
|
"""
|
|
|
|
|
user_id: str
|
|
|
|
|
type: Literal["text", "publicMsg", "file", "image", "video", "location", "chathistory", "site", "attachment", "url"]
|
|
|
|
|
content: str
|
|
|
|
|
addition: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app = FastAPI(
|
|
|
|
|
title="WiseFlow Union Backend",
|
|
|
|
|
description="From Wiseflow Team.",
|
2024-06-21 10:05:33 +08:00
|
|
|
|
version="0.3.0",
|
2024-06-15 15:41:31 +08:00
|
|
|
|
openapi_url="/openapi.json"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
app.add_middleware(
|
|
|
|
|
CORSMiddleware,
|
|
|
|
|
allow_origins=["*"],
|
|
|
|
|
allow_credentials=True,
|
|
|
|
|
allow_methods=["*"],
|
|
|
|
|
allow_headers=["*"],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/")
|
|
|
|
|
def read_root():
|
2024-06-21 10:05:33 +08:00
|
|
|
|
msg = "Hello, this is Wise Union Backend, version 0.3.0"
|
2024-06-15 15:41:31 +08:00
|
|
|
|
return {"msg": msg}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/feed")
|
|
|
|
|
async def call_to_feed(background_tasks: BackgroundTasks, request: Request):
|
2024-06-19 10:05:10 +08:00
|
|
|
|
background_tasks.add_task(message_manager, _input=request.model_dump())
|
2024-06-15 15:41:31 +08:00
|
|
|
|
return {"msg": "received well"}
|