Spaces:
Configuration error

truevis commited on
Commit
52d7cf8
1 Parent(s): 344d828
__pycache__/firebase_logging.cpython-312.pyc ADDED
Binary file (1.75 kB). View file
 
app.py CHANGED
@@ -7,7 +7,7 @@ import tiktoken
7
  import re
8
  import openai
9
  # import firebase_stripe_auth
10
-
11
  EMBEDDINGS_MODEL = 'text-embedding-3-small'
12
  groq_api_key = st.secrets["GROQ_API_KEY"]
13
  pinecone_api_key = st.secrets["PINECONE_API_KEY"]
@@ -55,7 +55,8 @@ about = """
55
  - Enter your question in the chat box on the right.
56
  - Choose how many pages of "Results" you would like to get from the knowledge base and added to the AI prompt. Increase the number to extract more information from the knowledge base.
57
  - After the first prompt, choose whether you want another knowledge base search for the next prompt using the button below.
58
- - All the PDF pages from the knowledge base are published online and citable. Each PDF page has a link at the bottom going directly the the PDF source page so it can be seen in context.
 
59
  - hudbot version 0.1 (c) 2024 DocMind AI
60
  """
61
 
@@ -200,6 +201,9 @@ def generate_response(user_input):
200
  except Exception as e:
201
  # Handle the exception
202
  error_message = f"An error occurred while generating the response: {str(e)}"
 
 
 
203
  yield error_message
204
  # You can also log the error or take any other necessary action
205
  print(error_message)
@@ -266,7 +270,9 @@ prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)]
266
 
267
  if user_prompt := st.chat_input("What can I help you with about HUD?"):
268
  original_user_prompt = user_prompt
269
-
 
 
270
  if st.session_state['query_pinecone_toggle']:
271
  user_prompt = get_db_results_new_prompt(user_prompt)
272
  else:
@@ -277,11 +283,18 @@ if user_prompt := st.chat_input("What can I help you with about HUD?"):
277
  with st.spinner("Generating response..."):
278
  try:
279
  response = st.write_stream(generate_response(user_prompt))
 
 
 
 
280
  # If no exception occurred, append the response to the messages
281
  st.session_state.messages.append(("assistant", response))
282
  except Exception as e:
283
  error_message = f"An error occurred while generating the response: {str(e)}"
284
  st.error(error_message)
 
 
 
285
  response = ""
286
  # You can also log the error or take any other necessary action
287
  print(error_message)
 
7
  import re
8
  import openai
9
  # import firebase_stripe_auth
10
+ from utils.firebase_logging import init_firebase, log_to_firestore
11
  EMBEDDINGS_MODEL = 'text-embedding-3-small'
12
  groq_api_key = st.secrets["GROQ_API_KEY"]
13
  pinecone_api_key = st.secrets["PINECONE_API_KEY"]
 
55
  - Enter your question in the chat box on the right.
56
  - Choose how many pages of "Results" you would like to get from the knowledge base and added to the AI prompt. Increase the number to extract more information from the knowledge base.
57
  - After the first prompt, choose whether you want another knowledge base search for the next prompt using the button below.
58
+ - The PDF pages from the knowledge base are published online and citable. Each PDF page has a link at the bottom going directly the the PDF source page so it can be seen in context.
59
+ - This app works best on desktop browsers and is not yet optimized for mobile devices.
60
  - hudbot version 0.1 (c) 2024 DocMind AI
61
  """
62
 
 
201
  except Exception as e:
202
  # Handle the exception
203
  error_message = f"An error occurred while generating the response: {str(e)}"
204
+ message = f"hud,anon,generate_response,{e}"
205
+ level = "ERROR"
206
+ log_to_firestore("docmind-421208", message, level)
207
  yield error_message
208
  # You can also log the error or take any other necessary action
209
  print(error_message)
 
270
 
271
  if user_prompt := st.chat_input("What can I help you with about HUD?"):
272
  original_user_prompt = user_prompt
273
+ message = f"hud,anon,p,{user_prompt[:200]}"
274
+ level = "INFO"
275
+ log_to_firestore("docmind-421208", message, level)
276
  if st.session_state['query_pinecone_toggle']:
277
  user_prompt = get_db_results_new_prompt(user_prompt)
278
  else:
 
283
  with st.spinner("Generating response..."):
284
  try:
285
  response = st.write_stream(generate_response(user_prompt))
286
+ message = f"hud,anon,r,{response[:200]}"
287
+ print(message)
288
+ level = "INFO"
289
+ log_to_firestore("docmind-421208", message, level)
290
  # If no exception occurred, append the response to the messages
291
  st.session_state.messages.append(("assistant", response))
292
  except Exception as e:
293
  error_message = f"An error occurred while generating the response: {str(e)}"
294
  st.error(error_message)
295
+ message = f"hud,anon,show_response,{e}"
296
+ level = "ERROR"
297
+ log_to_firestore("docmind-421208", message, level)
298
  response = ""
299
  # You can also log the error or take any other necessary action
300
  print(error_message)
utils/__pycache__/firebase_logging.cpython-312.pyc ADDED
Binary file (1.76 kB). View file
 
utils/firebase_logging.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import firebase_admin
2
+ from firebase_admin import credentials, firestore
3
+ import streamlit as st
4
+ def init_firebase(project_id):
5
+ if not firebase_admin._apps:
6
+ firebase_creds = credentials.Certificate({
7
+ "type": "service_account",
8
+ "project_id": project_id,
9
+ "private_key_id": st.secrets["private_key_id"],
10
+ "private_key": st.secrets["private_key"].replace('\\n', '\n'),
11
+ "client_email": st.secrets["client_email"],
12
+ "client_id": st.secrets["client_id"],
13
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
14
+ "token_uri": "https://oauth2.googleapis.com/token",
15
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
16
+ "client_x509_cert_url": st.secrets["client_x509_cert_url"]
17
+ })
18
+ firebase_admin.initialize_app(firebase_creds)
19
+ return firestore.client()
20
+
21
+ def log_to_firestore(project_id, message, level="INFO"):
22
+ db = init_firebase(project_id)
23
+ doc_ref = db.collection('logs').document()
24
+ doc_ref.set({
25
+ 'message': message,
26
+ 'level': level,
27
+ 'timestamp': firestore.SERVER_TIMESTAMP
28
+ })