mirror of
http://88.130.71.182:3000/BlitTech/contexta_be.git
synced 2026-06-13 08:56:20 +00:00
fixed the RAg in test pipeline issue
This commit is contained in:
@@ -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}
|
||||
Reference in New Issue
Block a user