Skip to content

Commit 6c4159d

Browse files
committed
feat: fixed api & added total tokens processed
1 parent 8d748b2 commit 6c4159d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

server/api/metrics.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,14 @@ def get_all_chatbot_ratings(token: Annotated[str, Header()], db: Session = Depen
9494
username = get_user_from_jwt(token)
9595
verify_user(username)
9696
metrics = []
97-
chatbot_user_ratings = []
98-
developer_ratings = []
99-
openai_ratings = []
100-
total_chatbot_user_ratings = 0
101-
total_developer_ratings = 0
102-
total_openai_ratings = 0
10397
chatbots = get_chatbots_from_username(username) # type: ignore
10498

10599
for chatbot in chatbots:
100+
chatbot_user_ratings = []
101+
developer_ratings = []
102+
openai_ratings = []
106103
bot_metrics = {}
104+
total_tokens_processed = 0
107105
total_chatbot_conversations = 0
108106
sum_chatbot_user_ratings = 0
109107
sum_developer_ratings = 0
@@ -112,6 +110,9 @@ def get_all_chatbot_ratings(token: Annotated[str, Header()], db: Session = Depen
112110
avg_developer_ratings = 0
113111
avg_openai_ratings = 0
114112
total_ratings = 0
113+
total_chatbot_user_ratings = 0
114+
total_developer_ratings = 0
115+
total_openai_ratings = 0
115116
chatbot_id = chatbot.id
116117
prompts = get_prompts_from_chatbot_id(chatbot_id)
117118
for prompt in prompts:
@@ -127,7 +128,7 @@ def get_all_chatbot_ratings(token: Annotated[str, Header()], db: Session = Depen
127128
openai_ratings.append(prompt.gpt_rating)
128129
sum_openai_ratings += prompt.gpt_rating
129130
total_openai_ratings += 1
130-
131+
total_tokens_processed += prompt.num_tokens
131132
total_chatbot_conversations += len(prompts)
132133

133134
sum_of_all_ratings = sum_chatbot_user_ratings + sum_developer_ratings + sum_openai_ratings
@@ -140,6 +141,7 @@ def get_all_chatbot_ratings(token: Annotated[str, Header()], db: Session = Depen
140141

141142
bot_metrics = {
142143
"total_conversations": total_chatbot_conversations,
144+
"total_tokens_processed": total_tokens_processed,
143145
"no_of_conversations_rated_by_developer": len(developer_ratings),
144146
"no_of_conversations_rated_by_end_user": len(chatbot_user_ratings),
145147
"no_of_conversations_rated_by_openai": len(openai_ratings),

0 commit comments

Comments
 (0)