Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the create read update delete api of bot #92

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 60 additions & 4 deletions server/routers/bot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
from fastapi import APIRouter, Depends, HTTPException, Query
from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, Query, Body, Path
from typing import Optional, List
from pydantic import BaseModel
from db.supabase.client import get_client

class BotCreateRequest(BaseModel):
uid: str
avatar: Optional[str] = None
description: Optional[str] = None
prompt: Optional[str] = None
files: Optional[List[str]] = None # 假设为文件的URL或标识符列表
enable_img_generation: Optional[bool] = None
label: Optional[str] = None
name: Optional[str] = None
starters: Optional[List[str]] = None # 假设为起始文本列表
voice: Optional[str] = None
public: Optional[bool] = None
class BotUpdateRequest(BaseModel):
avatar: Optional[str] = None
description: Optional[str] = None
prompt: Optional[str] = None
files: Optional[List[str]] = None
enable_img_generation: Optional[bool] = None
label: Optional[str] = None
name: Optional[str] = None
starters: Optional[List[str]] = None
voice: Optional[str] = None
public: Optional[bool] = None
router = APIRouter(
prefix="/api/bot",
tags=["bot"],
Expand All @@ -25,4 +48,37 @@ def get_bot_detail(id: Optional[str] = Query(None, description="Filter bots by p
supabase = get_client()
data = supabase.table("bots").select('id, created_at, updated_at, avatar, description, enable_img_generation, label, name, starters, voice, public').eq('id', id).execute()
return { "data": data.data, "status": 200}


@router.get("/config")
def get_bot_config(id: Optional[str] = Query(None, description="Filter bots by personal category")):
uid = "google-oauth2|110531372948747483359"
if not id or not uid:
return{
"error": "Auth failed",
"status": 401
}
else :
supabase = get_client()
data = supabase.table("bots").select('*').eq('id', id).eq('uid', uid).execute()
return { "data": data.data, "status": 200}

@router.post("/create", status_code=200)
def create_bot(bot_data: BotCreateRequest):
supabase = get_client()
bot_data.uid = "u123456"
response = supabase.table("bots").insert(bot_data.dict()).execute()
return {"status": 200}

@router.put("/update/{id}", status_code=200)
def update_bot(id: str, bot_data: BotUpdateRequest = Body(...)):
supabase = get_client()
uid = "u123456"
response = supabase.table("bots").update(bot_data.dict()).eq("id", id).eq("uid", uid).execute()
return {"status": 200}

@router.delete("/delete/{id}", status_code=200)
def delete_bot(id: str = Path(..., description="The ID of the bot to delete")):
supabase = get_client()
uid = "u123456"
response = supabase.table("bots").delete().eq("id", id).eq("uid", uid).execute()
return {"status": 200}