Spaces:
Running
Running
Omar Solano
commited on
add save_completion function (#46)
Browse files
app.py
CHANGED
@@ -54,6 +54,19 @@ logger = logging.getLogger(__name__)
|
|
54 |
logging.basicConfig(level=logging.INFO)
|
55 |
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
def log_likes(completion: Completion, like_data: gr.LikeData):
|
58 |
collection = "liked_data-test"
|
59 |
|
@@ -217,10 +230,15 @@ with gr.Blocks(
|
|
217 |
|
218 |
submit.click(user, [question, chatbot], [question, chatbot], queue=False).then(
|
219 |
get_answer, inputs=[chatbot, source_selection], outputs=[chatbot, completion]
|
220 |
-
).then(add_sources, inputs=[chatbot, completion], outputs=[chatbot])
|
|
|
|
|
|
|
221 |
question.submit(user, [question, chatbot], [question, chatbot], queue=False).then(
|
222 |
get_answer, inputs=[chatbot, source_selection], outputs=[chatbot, completion]
|
223 |
-
).then(add_sources, inputs=[chatbot, completion], outputs=[chatbot])
|
|
|
|
|
224 |
|
225 |
chatbot.like(log_likes, completion)
|
226 |
|
|
|
54 |
logging.basicConfig(level=logging.INFO)
|
55 |
|
56 |
|
57 |
+
def save_completion(completion: Completion, question: gr.Textbox):
|
58 |
+
collection = "completion_data-hf"
|
59 |
+
|
60 |
+
completion_json = completion.to_json(
|
61 |
+
columns_to_ignore=["embedding", "similarity", "similarity_to_answer"]
|
62 |
+
)
|
63 |
+
try:
|
64 |
+
cfg.mongo_db[collection].insert_one(completion_json)
|
65 |
+
logger.info("Completion saved to db")
|
66 |
+
except:
|
67 |
+
logger.info("Something went wrong logging completion to db")
|
68 |
+
|
69 |
+
|
70 |
def log_likes(completion: Completion, like_data: gr.LikeData):
|
71 |
collection = "liked_data-test"
|
72 |
|
|
|
230 |
|
231 |
submit.click(user, [question, chatbot], [question, chatbot], queue=False).then(
|
232 |
get_answer, inputs=[chatbot, source_selection], outputs=[chatbot, completion]
|
233 |
+
).then(add_sources, inputs=[chatbot, completion], outputs=[chatbot]).then(
|
234 |
+
save_completion, inputs=[completion]
|
235 |
+
)
|
236 |
+
|
237 |
question.submit(user, [question, chatbot], [question, chatbot], queue=False).then(
|
238 |
get_answer, inputs=[chatbot, source_selection], outputs=[chatbot, completion]
|
239 |
+
).then(add_sources, inputs=[chatbot, completion], outputs=[chatbot]).then(
|
240 |
+
save_completion, inputs=[completion]
|
241 |
+
)
|
242 |
|
243 |
chatbot.like(log_likes, completion)
|
244 |
|