CoolFace
Apppublic

Pamudu13/gemma-3-chat

sourceHugging Faceupdated 25d agoView on Hugging Face
0likes
affection_api.py30 linesDownload Raw Back to py
1from fastapi import APIRouter, Body, HTTPException2from typing import Dict, Any3from py.affection_system import load_affection_data, save_affection_data4 5# 创建羁绊系统的数据路由6router = APIRouter(prefix="/api/affection", tags=["Affection System"])7 8@router.get("/get_data")9async def get_affection_data_api():10    """11    获取所有用户的羁绊数据12    返回格式: {"小包": {"love": 10, "Familiarity": 5}, "张三": {"love": 2}}13    """14    try:15        data = await load_affection_data()16        return data17    except Exception as e:18        raise HTTPException(status_code=500, detail=f"读取羁绊数据失败: {str(e)}")19 20@router.post("/save_data")21async def save_affection_data_api(data: Dict[str, Any] = Body(...)):22    """23    全量保存羁绊数据 (覆盖保存)24    接收格式: {"小包": {"love": 10, "Familiarity": 5}}25    """26    try:27        await save_affection_data(data)28        return {"status": "success", "message": "羁绊数据保存成功"}29    except Exception as e:30        raise HTTPException(status_code=500, detail=f"保存羁绊数据失败: {str(e)}")