From d04212d26338e029191dc2e5f8f7fa53c4b04f38 Mon Sep 17 00:00:00 2001 From: yingying Date: Thu, 22 Aug 2024 09:38:01 +0800 Subject: [PATCH 1/3] style: fix flex --- lui/src/Chat/components/ChatItemRender.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lui/src/Chat/components/ChatItemRender.tsx b/lui/src/Chat/components/ChatItemRender.tsx index 2f6accab..2216d116 100644 --- a/lui/src/Chat/components/ChatItemRender.tsx +++ b/lui/src/Chat/components/ChatItemRender.tsx @@ -36,7 +36,7 @@ const ChatItemRender: FC = ({ }} /> )} -
+
{title} {content}
From eb8d29b34a63da86f2745484648c00804fd8ef35 Mon Sep 17 00:00:00 2001 From: yingying Date: Thu, 22 Aug 2024 09:45:52 +0800 Subject: [PATCH 2/3] fix: order the bot list by update_time --- server/routers/bot.py | 175 ++++++++++++++++++++++++++++++------------ 1 file changed, 127 insertions(+), 48 deletions(-) diff --git a/server/routers/bot.py b/server/routers/bot.py index 7482fe33..51dccdf9 100644 --- a/server/routers/bot.py +++ b/server/routers/bot.py @@ -13,105 +13,184 @@ responses={404: {"description": "Not found"}}, ) + @router.get("/list") -def get_bot_list(personal: Optional[str] = Query(None, description="Filter bots by personal category"), name: Optional[str] = Query(None, description="Filter bots by name"), user_id: Annotated[str | None, Depends(get_user_id)] = None): +def get_bot_list( + personal: Optional[str] = Query( + None, description="Filter bots by personal category" + ), + name: Optional[str] = Query(None, description="Filter bots by name"), + user_id: Annotated[str | None, Depends(get_user_id)] = None, +): try: supabase = get_client() - query = supabase.table("bots").select("id, created_at, updated_at, avatar, description, name, public, starters, uid") - if personal == 'true': + query = supabase.table("bots").select( + "id, created_at, updated_at, avatar, description, name, public, starters, uid" + ) + if personal == "true": if not user_id: return {"data": [], "personal": personal} - query = query.eq('uid', user_id) + query = query.eq("uid", user_id).order("updated_at", desc=True) if name: - query = supabase.table("bots").select("id, created_at, updated_at, avatar, description, name, public, starters, uid").filter("name", "like", f"%{name}%") - - query = query.eq('public', True) if not personal or personal != 'true' else query - + query = ( + supabase.table("bots") + .select( + "id, created_at, updated_at, avatar, description, name, public, starters, uid" + ) + .filter("name", "like", f"%{name}%") + ) + + query = ( + query.eq("public", True).order("updated_at", desc=True) + if not personal or personal != "true" + else query + ) + data = query.execute() if not data or not data.data: return {"data": [], "personal": personal} return {"data": data.data, "personal": personal} - + except Exception as e: - return JSONResponse(content={"success": False, "errorMessage": str(e)}, status_code=500) + return JSONResponse( + content={"success": False, "errorMessage": str(e)}, status_code=500 + ) + @router.get("/detail") -def get_bot_detail(id: Optional[str] = Query(None, description="Filter bots by personal category")): - if not id: - return{ - "error": "Incomplete parameters", - "status": 400 - } +def get_bot_detail( + id: Optional[str] = Query(None, description="Filter bots by personal category") +): + if not id: + return {"error": "Incomplete parameters", "status": 400} else: try: supabase = get_client() - data = supabase.table("bots").select('id, created_at, updated_at, avatar, description, name, starters, public, hello_message').eq('id', id).execute() - return { "data": data.data, "status": 200} + data = ( + supabase.table("bots") + .select( + "id, created_at, updated_at, avatar, description, name, starters, public, hello_message" + ) + .eq("id", id) + .execute() + ) + return {"data": data.data, "status": 200} except Exception as e: - return JSONResponse(content={"success": False, "errorMessage": str(e)}, status_code=500) + return JSONResponse( + content={"success": False, "errorMessage": str(e)}, status_code=500 + ) + @router.get("/config") -def get_bot_config(id: Optional[str] = Query(None, description="Filter bots by personal category"), user_id: Annotated[str | None, Depends(get_user_id)] = None): +def get_bot_config( + id: Optional[str] = Query(None, description="Filter bots by personal category"), + user_id: Annotated[str | None, Depends(get_user_id)] = None, +): try: supabase = get_client() - data = supabase.table("bots").select('*').eq('id', id).eq('uid', user_id).execute() - return { "data": data.data, "status": 200} + data = ( + supabase.table("bots").select("*").eq("id", id).eq("uid", user_id).execute() + ) + return {"data": data.data, "status": 200} except Exception as e: return JSONResponse(content={"success": False, "errorMessage": e}) + @router.post("/create", status_code=200) -async def create_bot(bot_data: BotCreateRequest, user_id: Annotated[str | None, Depends(get_user_id)] = None): +async def create_bot( + bot_data: BotCreateRequest, + user_id: Annotated[str | None, Depends(get_user_id)] = None, +): try: res = await bot_builder(user_id, **bot_data.model_dump()) if not res: - return JSONResponse(content={"success": False, "errorMessage": "仓库不存在,生成失败"}, status_code=500) + return JSONResponse( + content={"success": False, "errorMessage": "仓库不存在,生成失败"}, + status_code=500, + ) return res except Exception as e: - return JSONResponse(content={"success": False, "errorMessage": str(e)}, status_code=500) + return JSONResponse( + content={"success": False, "errorMessage": str(e)}, status_code=500 + ) + @router.post("/config/generator", status_code=200) -async def bot_generator(bot_data: BotCreateRequest, user_id: Annotated[str | None, Depends(get_user_id)] = None): +async def bot_generator( + bot_data: BotCreateRequest, + user_id: Annotated[str | None, Depends(get_user_id)] = None, +): try: - res = await bot_info_generator(user_id, **bot_data.model_dump()) + res = await bot_info_generator(user_id, **bot_data.model_dump()) if not res: - return JSONResponse(content={"success": False, "errorMessage": "仓库不存在,生成失败"}) + return JSONResponse( + content={"success": False, "errorMessage": "仓库不存在,生成失败"} + ) return JSONResponse(content={"success": True, "data": res}) except Exception as e: - return JSONResponse(content={"success": False, "errorMessage": str(e)}, status_code=500) + return JSONResponse( + content={"success": False, "errorMessage": str(e)}, status_code=500 + ) + @router.put("/update/{id}", status_code=200) -def update_bot(id: str, bot_data: BotUpdateRequest, user_id: Annotated[str | None, Depends(get_user_id)] = None): +def update_bot( + id: str, + bot_data: BotUpdateRequest, + user_id: Annotated[str | None, Depends(get_user_id)] = None, +): if not id: - return { - "error": "Incomplete parameters", - "status": 400 - } + return {"error": "Incomplete parameters", "status": 400} try: - update_fields = {key: value for key, value in bot_data.model_dump(exclude_unset=True).items() if value is not None} - + update_fields = { + key: value + for key, value in bot_data.model_dump(exclude_unset=True).items() + if value is not None + } + if not update_fields: - return JSONResponse(content={"success": False, "errorMessage": "No fields to update"}, status_code=400) - + return JSONResponse( + content={"success": False, "errorMessage": "No fields to update"}, + status_code=400, + ) + supabase = get_client() - response = supabase.table("bots").update(update_fields).eq("id", id).eq("uid", user_id).execute() - + response = ( + supabase.table("bots") + .update(update_fields) + .eq("id", id) + .eq("uid", user_id) + .execute() + ) + if not response.data: - return JSONResponse(content={"success": False, "errorMessage": "bot 不存在,更新失败"}) - + return JSONResponse( + content={"success": False, "errorMessage": "bot 不存在,更新失败"} + ) + return JSONResponse(content={"success": True}) except Exception as e: - return JSONResponse(content={"success": False, "errorMessage": str(e)}, status_code=500) + return JSONResponse( + content={"success": False, "errorMessage": str(e)}, status_code=500 + ) + @router.delete("/delete/{id}", status_code=status.HTTP_200_OK) async def delete_bot( - id: str = Path(..., description="The ID of the bot to delete"), - user_id: Annotated[str | None, Depends(get_user_id)] = None + id: str = Path(..., description="The ID of the bot to delete"), + user_id: Annotated[str | None, Depends(get_user_id)] = None, ): try: supabase = get_client() - response = supabase.table("bots").delete().eq("id", id).eq("uid", user_id).execute() + response = ( + supabase.table("bots").delete().eq("id", id).eq("uid", user_id).execute() + ) if not response.data: - return JSONResponse(content={"success": False, "errorMessage": "bot 不存在,删除失败"}) + return JSONResponse( + content={"success": False, "errorMessage": "bot 不存在,删除失败"} + ) return JSONResponse(content={"success": True}) except Exception as e: - return JSONResponse(content={"success": False, "errorMessage": str(e)}, status_code=500) + return JSONResponse( + content={"success": False, "errorMessage": str(e)}, status_code=500 + ) From 5137c33e2a2c60285482a7d1c65a6fa4c4f7af97 Mon Sep 17 00:00:00 2001 From: yingying Date: Thu, 22 Aug 2024 10:03:49 +0800 Subject: [PATCH 3/3] chore: release thr lui --- client/package.json | 2 +- client/yarn.lock | 8 ++++---- lui/package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/package.json b/client/package.json index e2e13e4f..bf199f6c 100644 --- a/client/package.json +++ b/client/package.json @@ -39,7 +39,7 @@ "lottie-react": "^2.4.0", "next": "14.0.1", "openai": "^4.24.7", - "petercat-lui": "^0.1.19", + "petercat-lui": "^0.1.20", "postcss": "^8.4.41", "react": "18.2.0", "react-dom": "18.2.0", diff --git a/client/yarn.lock b/client/yarn.lock index a8e08250..eaff9164 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -8504,10 +8504,10 @@ path-type@^4.0.0: resolved "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== -petercat-lui@^0.1.19: - version "0.1.19" - resolved "https://registry.npmjs.org/petercat-lui/-/petercat-lui-0.1.19.tgz#4d910fb664107ea694fbdfeffdfc3060ba5172cc" - integrity sha512-8MMy1NarNcY/dwl2P5YbDNy1NdmYNRPOe0mJgkp0IQRnodV44KFNaLJ9HDyXxagRYylXPF/MGlGd00GYgX6bSg== +petercat-lui@^0.1.20: + version "0.1.20" + resolved "https://registry.npmjs.org/petercat-lui/-/petercat-lui-0.1.20.tgz#3b38a0f946ff78f189f4d443505f55bd60f3cd2f" + integrity sha512-vpq24RW5wWqgGIXplJ+3KbjfFLnCXFvO8f2cp5TytL4WAKwtl6KwUhz6f66ZSQmkw3NxGLxXTC7e194/83GP2A== dependencies: "@ant-design/icons" "^5.3.5" "@ant-design/pro-chat" "^1.9.0" diff --git a/lui/package.json b/lui/package.json index a7cac2da..0523b1a1 100644 --- a/lui/package.json +++ b/lui/package.json @@ -1,6 +1,6 @@ { "name": "petercat-lui", - "version": "0.1.19", + "version": "0.1.20", "description": "A react library developed with dumi", "module": "dist/esm/index.js", "types": "dist/esm/index.d.ts",