Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
binding response to analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
codebanesr committed Dec 8, 2023
1 parent 0663aaa commit 3289cfd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions llm-server/routes/analytics/analytics_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from shared.models.opencopilot_db import engine
from sqlalchemy.dialects.mysql import insert

def upsert_analytics_record(chatbot_id: str, successful_operations: int, total_operations: int, user_id: str):
def upsert_analytics_record(chatbot_id: str, successful_operations: int, total_operations: int):
Session = sessionmaker(bind=engine)
session = Session()

insert_stmt = insert(Analytics).values(
chatbot_id=chatbot_id,
successful_operations=successful_operations,
total_operations=total_operations,
user_id=user_id
)

session.execute(insert_stmt)
Expand Down
6 changes: 5 additions & 1 deletion llm-server/routes/chat/chat_controller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import cast

from flask import jsonify, Blueprint, request, Response, abort, Request
from routes.analytics.analytics_service import upsert_analytics_record
from routes.chat.chat_dto import ChatInput
from utils.get_logger import CustomLogger
from utils.llm_consts import X_App_Name
Expand Down Expand Up @@ -160,13 +161,16 @@ async def send_chat():
)

if response_data["response"]:
upsert_analytics_record(chatbot_id=str(bot.id), successful_operations=1, total_operations=1)
create_chat_history(str(bot.id), session_id, True, message)
create_chat_history(
str(bot.id),
session_id,
False,
response_data["response"] or response_data["error"],
response_data["response"] or response_data["error"] or "",
)
elif response_data["error"]:
upsert_analytics_record(chatbot_id=str(bot.id), successful_operations=0, total_operations=1)

return jsonify(
{"type": "text", "response": {"text": response_data["response"]}}
Expand Down
1 change: 0 additions & 1 deletion llm-server/shared/models/opencopilot_db/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Analytics(Base):
chatbot_id = Column(String, primary_key=True)
successful_operations = Column(Integer)
total_operations = Column(Integer)
user_id = Column(String)

def __init__(self, chatbot_id, user_id):
self.chatbot_id = chatbot_id
Expand Down

0 comments on commit 3289cfd

Please sign in to comment.