From f00802dd6bcb182935d9d23652094c2ddd5cc663 Mon Sep 17 00:00:00 2001 From: Siddhant Rai Date: Wed, 19 Mar 2025 10:25:46 +0530 Subject: [PATCH] fix: llm tests failing --- application/api/user/routes.py | 24 +++++++++--------------- application/llm/base.py | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/application/api/user/routes.py b/application/api/user/routes.py index 87f23cdc..f3599c7e 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -1368,22 +1368,22 @@ class GetMessageAnalytics(Resource): group_format = "%Y-%m-%d" try: + match_stage = { + "$match": { + "user": user, + } + } + if api_key: + match_stage["$match"]["api_key"] = api_key + pipeline = [ - # Initial match for user and API key if provided - { - "$match": { - "user": user, - "api_key": api_key if api_key else {"$exists": False}, - } - }, + match_stage, {"$unwind": "$queries"}, - # Match queries within the time range { "$match": { "queries.timestamp": {"$gte": start_date, "$lte": end_date} } }, - # Group by formatted timestamp { "$group": { "_id": { @@ -1395,7 +1395,6 @@ class GetMessageAnalytics(Resource): "count": {"$sum": 1}, } }, - # Sort by timestamp {"$sort": {"_id": 1}}, ] @@ -1546,8 +1545,6 @@ class GetTokenAnalytics(Resource): } if api_key: match_stage["$match"]["api_key"] = api_key - else: - match_stage["$match"]["api_key"] = {"$exists": False} token_usage_data = token_usage_collection.aggregate( [ @@ -1683,10 +1680,7 @@ class GetFeedbackAnalytics(Resource): } if api_key: match_stage["$match"]["api_key"] = api_key - else: - match_stage["$match"]["api_key"] = {"$exists": False} - # Unwind the queries array to process each query separately pipeline = [ match_stage, {"$unwind": "$queries"}, diff --git a/application/llm/base.py b/application/llm/base.py index 39c69499..0fce208c 100644 --- a/application/llm/base.py +++ b/application/llm/base.py @@ -5,7 +5,7 @@ from application.usage import gen_token_usage, stream_token_usage class BaseLLM(ABC): - def __init__(self, decoded_token): + def __init__(self, decoded_token=None): self.decoded_token = decoded_token self.token_usage = {"prompt_tokens": 0, "generated_tokens": 0}