fixed the RAg in test pipeline issue

This commit is contained in:
belviskhoremk
2026-04-26 18:51:48 +00:00
parent 205d9d7901
commit 97a501097d
14 changed files with 249 additions and 57 deletions

View File

@@ -175,13 +175,21 @@ async def rate_chatbot(
user=Depends(get_current_user),
):
supabase = get_supabase()
chatbot = supabase.table("chatbots").select("id, average_rating").eq("id", chatbot_id).eq("is_published", True).execute()
chatbot = supabase.table("chatbots") \
.select("id, average_rating, rating_count") \
.eq("id", chatbot_id).eq("is_published", True).execute()
if not chatbot.data:
raise HTTPException(status_code=404, detail="Chatbot not found")
# Simple rating update (average)
current = chatbot.data[0].get("average_rating") or rating.rating
new_avg = (current + rating.rating) / 2
row = chatbot.data[0]
current_avg = row.get("average_rating") or 0.0
current_count = row.get("rating_count") or 0
supabase.table("chatbots").update({"average_rating": round(new_avg, 1)}).eq("id", chatbot_id).execute()
return {"message": "Rating submitted", "new_average": round(new_avg, 1)}
new_count = current_count + 1
new_avg = round((current_avg * current_count + rating.rating) / new_count, 2)
supabase.table("chatbots").update({
"average_rating": new_avg,
"rating_count": new_count,
}).eq("id", chatbot_id).execute()
return {"average_rating": new_avg, "rating_count": new_count}