Kye Gomez commited on
Commit
00caf10
β€’
1 Parent(s): 8534dd6

[FEAT][Logging]

Browse files
Files changed (2) hide show
  1. app.py +39 -31
  2. mongod_db.py +3 -1
app.py CHANGED
@@ -2,22 +2,10 @@ import streamlit as st
2
  import random
3
  from helpers import query_you_com, query_tavily, query_perplexity
4
  from mongod_db import MongoDBHandler
 
 
5
 
6
- from pydantic import BaseModel
7
- from typing import List
8
-
9
-
10
- db_handler = MongoDBHandler()
11
-
12
-
13
- class UsageLog(BaseModel):
14
- question: str
15
- selected_functions: List[str]
16
- answer_a: str
17
- answer_b: str
18
- feedback: str
19
- timestamp: str
20
-
21
 
22
  # Set Streamlit to wide mode
23
  st.set_page_config(layout="wide")
@@ -32,6 +20,22 @@ def ProcessQuestion(question):
32
  # Get answers from the selected functions
33
  answer_a = selected_functions[0](question)
34
  answer_b = selected_functions[1](question)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  return answer_a, answer_b
37
 
@@ -47,7 +51,7 @@ if "question" not in st.session_state:
47
  st.session_state["question"] = ""
48
 
49
  # Streamlit app layout
50
- st.title("Chatbot Comparison")
51
 
52
  # Create columns for the input and model selection
53
  input_col, control_col = st.columns([4, 1])
@@ -83,29 +87,33 @@ if submit_button:
83
  # Display results if available in session state
84
  if st.session_state["results_displayed"]:
85
  col1, col2 = st.columns(2)
86
-
87
  with col1:
88
  st.write("### Output A")
89
  st.write(st.session_state["answer_a"])
90
-
91
  with col2:
92
  st.write("### Output B")
93
  st.write(st.session_state["answer_b"])
 
94
 
95
- feedback_col = st.columns([1, 1, 1, 1])
96
-
97
- with feedback_col[0]:
98
- if st.button("A is better πŸ₯‡"):
99
- st.write("You selected: A is better")
100
 
101
- with feedback_col[1]:
102
- if st.button("B is better πŸ₯ˆ"):
103
- st.write("You selected: B is better")
 
 
104
 
105
- with feedback_col[2]:
 
 
 
 
 
 
106
  if st.button("It's a Tie 🀝"):
107
- st.write("You selected: It's a Tie")
108
-
109
- with feedback_col[3]:
110
  if st.button("Both are bad πŸ‘Ž"):
111
- st.write("You selected: Both are bad")
 
2
  import random
3
  from helpers import query_you_com, query_tavily, query_perplexity
4
  from mongod_db import MongoDBHandler
5
+ from swarms.utils.loguru_logger import logger
6
+ import time
7
 
8
+ mongo = MongoDBHandler()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # Set Streamlit to wide mode
11
  st.set_page_config(layout="wide")
 
20
  # Get answers from the selected functions
21
  answer_a = selected_functions[0](question)
22
  answer_b = selected_functions[1](question)
23
+
24
+ # Log into mongodb
25
+ try:
26
+ logger.info(f"Logging question: {question}")
27
+ mongo.add(
28
+ {
29
+ "question": question,
30
+ "answer_a": answer_a,
31
+ "answer_b": answer_b,
32
+ "selected_functions": [f.__name__ for f in selected_functions],
33
+ "query_time": time.time(),
34
+ }
35
+ )
36
+ logger.info("Successfully logged into mongodb")
37
+ except Exception as e:
38
+ logger.error(f"Error logging into mongodb: {e}")
39
 
40
  return answer_a, answer_b
41
 
 
51
  st.session_state["question"] = ""
52
 
53
  # Streamlit app layout
54
+ st.title("Search Engine Agent Comparison")
55
 
56
  # Create columns for the input and model selection
57
  input_col, control_col = st.columns([4, 1])
 
87
  # Display results if available in session state
88
  if st.session_state["results_displayed"]:
89
  col1, col2 = st.columns(2)
 
90
  with col1:
91
  st.write("### Output A")
92
  st.write(st.session_state["answer_a"])
93
+ a_feedback_grid = st.columns(1)
94
  with col2:
95
  st.write("### Output B")
96
  st.write(st.session_state["answer_b"])
97
+ b_feedback_grid = st.columns(2)
98
 
99
+ # Create a placeholder for the feedback div
100
+ feedback_placeholder = st.empty()
 
 
 
101
 
102
+ def display_feedback(message):
103
+ feedback_placeholder.markdown(
104
+ f'<div style="position: fixed; bottom: 10px; left: 10px; background-color: #f0f0f0; padding: 10px; border-radius: 5px;">{message}</div>',
105
+ unsafe_allow_html=True,
106
+ )
107
 
108
+ with a_feedback_grid[0]:
109
+ if st.button("A is better πŸ₯‡"):
110
+ display_feedback("You selected: A is better")
111
+ with b_feedback_grid[0]:
112
+ if st.button("B is better πŸ’ͺ"):
113
+ display_feedback("You selected: B is better")
114
+ with a_feedback_grid[0]:
115
  if st.button("It's a Tie 🀝"):
116
+ display_feedback("You selected: It's a Tie")
117
+ with b_feedback_grid[0]:
 
118
  if st.button("Both are bad πŸ‘Ž"):
119
+ display_feedback("You selected: Both are bad")
mongod_db.py CHANGED
@@ -18,6 +18,8 @@ class MongoDBHandler:
18
  uri: str = mongo_db_uri(),
19
  db_name: str = "search-arena",
20
  collection_name: str = "search-arena-usage",
 
 
21
  ) -> None:
22
  """
23
  Initializes the MongoDBHandler with the specified database and collection.
@@ -27,7 +29,7 @@ class MongoDBHandler:
27
  db_name (str): The name of the database.
28
  collection_name (str): The name of the collection.
29
  """
30
- self.client = MongoClient(uri)
31
  self.db = self.client[db_name]
32
  self.collection = self.db[collection_name]
33
 
 
18
  uri: str = mongo_db_uri(),
19
  db_name: str = "search-arena",
20
  collection_name: str = "search-arena-usage",
21
+ *args,
22
+ **kwargs
23
  ) -> None:
24
  """
25
  Initializes the MongoDBHandler with the specified database and collection.
 
29
  db_name (str): The name of the database.
30
  collection_name (str): The name of the collection.
31
  """
32
+ self.client = MongoClient(uri, *args, **kwargs)
33
  self.db = self.client[db_name]
34
  self.collection = self.db[collection_name]
35