Louis-François Bouchard commited on
Commit
4c27275
1 Parent(s): b46dbf7

Email logger (#24)

Browse files

* Added email logger

* added new prompt to buster

* add reset text box on click

Files changed (2) hide show
  1. app.py +32 -5
  2. cfg.py +2 -2
app.py CHANGED
@@ -55,6 +55,21 @@ def log_likes(completion: Completion, like_data: gr.LikeData):
55
  logger.info("Something went wrong logging")
56
 
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  def format_sources(matched_documents: pd.DataFrame) -> str:
59
  if len(matched_documents) == 0:
60
  return ""
@@ -73,7 +88,7 @@ def format_sources(matched_documents: pd.DataFrame) -> str:
73
  # drop duplicates, keep highest ranking ones
74
  matched_documents = matched_documents.sort_values(
75
  "similarity_to_answer", ascending=False
76
- ).drop_duplicates("title", keep="first")
77
 
78
  # Revert back to correct display
79
  display_source_to_ui = {
@@ -172,10 +187,19 @@ with demo:
172
  )
173
  submit = gr.Button(value="Send", variant="secondary")
174
 
175
- examples = gr.Examples(
176
- examples=cfg.example_questions,
177
- inputs=question,
178
- )
 
 
 
 
 
 
 
 
 
179
 
180
  gr.Markdown(
181
  "This application uses ChatGPT to search the docs for relevant info and answer questions. "
@@ -193,5 +217,8 @@ with demo:
193
 
194
  chatbot.like(log_likes, completion)
195
 
 
 
 
196
  demo.queue(concurrency_count=CONCURRENCY_COUNT)
197
  demo.launch(debug=True, share=False)
 
55
  logger.info("Something went wrong logging")
56
 
57
 
58
+ def log_emails(email: gr.Textbox):
59
+ collection = "email_data-test"
60
+
61
+ logger.info(f"User reported {email=}")
62
+ email_document = {"email": email}
63
+
64
+ try:
65
+ cfg.mongo_db[collection].insert_one(email_document)
66
+ logger.info("")
67
+ except:
68
+ logger.info("Something went wrong logging")
69
+
70
+ return ""
71
+
72
+
73
  def format_sources(matched_documents: pd.DataFrame) -> str:
74
  if len(matched_documents) == 0:
75
  return ""
 
88
  # drop duplicates, keep highest ranking ones
89
  matched_documents = matched_documents.sort_values(
90
  "similarity_to_answer", ascending=False
91
+ ).drop_duplicates("title", keep="first")[:5]
92
 
93
  # Revert back to correct display
94
  display_source_to_ui = {
 
187
  )
188
  submit = gr.Button(value="Send", variant="secondary")
189
 
190
+ with gr.Row():
191
+ examples = gr.Examples(
192
+ examples=cfg.example_questions,
193
+ inputs=question,
194
+ )
195
+ with gr.Row():
196
+ email = gr.Textbox(
197
+ label="Want to receive updates about our AI tutor?",
198
+ placeholder="Enter your email here...",
199
+ lines=1,
200
+ scale=3,
201
+ )
202
+ submit_email = gr.Button(value="Submit", variant="secondary", scale=0)
203
 
204
  gr.Markdown(
205
  "This application uses ChatGPT to search the docs for relevant info and answer questions. "
 
217
 
218
  chatbot.like(log_likes, completion)
219
 
220
+ submit_email.click(log_emails, email, email)
221
+ email.submit(log_emails, email, email)
222
+
223
  demo.queue(concurrency_count=CONCURRENCY_COUNT)
224
  demo.launch(debug=True, share=False)
cfg.py CHANGED
@@ -106,7 +106,7 @@ Q:
106
  "Only respond with information inside the json documentation. DO NOT use additional information, even if you know the answer. "
107
  "If the answer is in the documentation, answer the question (depending on the questions and the variety of relevant information in the json documentation, answer in 5 paragraphs."
108
  "If the documentation does not discuss the topic related to the question, kindly respond that you cannot answer the question because it is not part of your knowledge. "
109
- "Here is the information you can use (json documentation): "
110
  ),
111
  "text_after_docs": (
112
  "REMEMBER:\n"
@@ -114,7 +114,7 @@ Q:
114
  "You are provided information found in the json documentation. "
115
  "Here are the rules you must follow:\n"
116
  "* Only respond with information inside the json documentation. DO NOT provide additional information, even if you know the answer. "
117
- "* If the answer is in the documentation, answer the question (depending on the questions and the variety of relevant information in the json documentation, answer in 5 paragraphs. "
118
  "* If the documentation does not discuss the topic related to the question, kindly respond that you cannot answer the question because it is not part of your knowledge. "
119
  "* Only use information summarized from the json documentation, do not respond otherwise. "
120
  "* Do not refer to the json documentation directly, but use the instructions provided within it to answer questions. "
 
106
  "Only respond with information inside the json documentation. DO NOT use additional information, even if you know the answer. "
107
  "If the answer is in the documentation, answer the question (depending on the questions and the variety of relevant information in the json documentation, answer in 5 paragraphs."
108
  "If the documentation does not discuss the topic related to the question, kindly respond that you cannot answer the question because it is not part of your knowledge. "
109
+ "Here is the information you can use (json documentation) in order: "
110
  ),
111
  "text_after_docs": (
112
  "REMEMBER:\n"
 
114
  "You are provided information found in the json documentation. "
115
  "Here are the rules you must follow:\n"
116
  "* Only respond with information inside the json documentation. DO NOT provide additional information, even if you know the answer. "
117
+ "* If the answer is in the documentation, answer the question (depending on the questions and the variety of relevant information in the json documentation. Your answer needs to be pertinent and not redundant giving a clear explanation as if you were a teacher. "
118
  "* If the documentation does not discuss the topic related to the question, kindly respond that you cannot answer the question because it is not part of your knowledge. "
119
  "* Only use information summarized from the json documentation, do not respond otherwise. "
120
  "* Do not refer to the json documentation directly, but use the instructions provided within it to answer questions. "