Spaces:
Running
Running
Louis-François Bouchard
Omar Solano
commited on
Commit
•
1c9a7e6
1
Parent(s):
36fbf7e
Add time data (#51)
Browse files* Openai activeloop data (#37)
* adding openai and activeloop data
* fixing issues with names
* concurrency
* black
* black
* revert to gradio3.50 for concurrency
---------
Co-authored-by: Omar Solano <omar@designstripe.com>
* ensure gradio version for HF
* Updates to files
* Push to advanced rag course
* edits to prompt
* Add datetime to mongodb logs
* tests for history
* add history and history length to database
* formatting
---------
Co-authored-by: Omar Solano <omar@designstripe.com>
app.py
CHANGED
@@ -55,7 +55,7 @@ logger = logging.getLogger(__name__)
|
|
55 |
logging.basicConfig(level=logging.INFO)
|
56 |
|
57 |
|
58 |
-
def save_completion(completion: Completion,
|
59 |
collection = "completion_data-hf"
|
60 |
|
61 |
# Convert completion to JSON and ignore certain columns
|
@@ -65,6 +65,8 @@ def save_completion(completion: Completion, question: gr.Textbox):
|
|
65 |
|
66 |
# Add the current date and time to the JSON
|
67 |
completion_json["timestamp"] = datetime.utcnow().isoformat()
|
|
|
|
|
68 |
|
69 |
try:
|
70 |
cfg.mongo_db[collection].insert_one(completion_json)
|
@@ -159,7 +161,6 @@ def get_empty_source_completion(user_input):
|
|
159 |
|
160 |
def get_answer(history, sources: Optional[list[str]] = None):
|
161 |
user_input = history[-1][0]
|
162 |
-
|
163 |
if len(sources) == 0:
|
164 |
completion = get_empty_source_completion(user_input)
|
165 |
|
@@ -175,7 +176,6 @@ def get_answer(history, sources: Optional[list[str]] = None):
|
|
175 |
|
176 |
for token in completion.answer_generator:
|
177 |
history[-1][1] += token
|
178 |
-
|
179 |
yield history, completion
|
180 |
|
181 |
|
@@ -204,7 +204,6 @@ with gr.Blocks(
|
|
204 |
)
|
205 |
|
206 |
chatbot = gr.Chatbot(elem_id="chatbot", show_copy_button=True)
|
207 |
-
|
208 |
with gr.Row():
|
209 |
question = gr.Textbox(
|
210 |
label="What's your question?",
|
@@ -237,13 +236,13 @@ with gr.Blocks(
|
|
237 |
submit.click(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 |
question.submit(user, [question, chatbot], [question, chatbot], queue=False).then(
|
244 |
get_answer, inputs=[chatbot, source_selection], outputs=[chatbot, completion]
|
245 |
).then(add_sources, inputs=[chatbot, completion], outputs=[chatbot]).then(
|
246 |
-
save_completion, inputs=[completion]
|
247 |
)
|
248 |
|
249 |
chatbot.like(log_likes, completion)
|
|
|
55 |
logging.basicConfig(level=logging.INFO)
|
56 |
|
57 |
|
58 |
+
def save_completion(completion: Completion, history):
|
59 |
collection = "completion_data-hf"
|
60 |
|
61 |
# Convert completion to JSON and ignore certain columns
|
|
|
65 |
|
66 |
# Add the current date and time to the JSON
|
67 |
completion_json["timestamp"] = datetime.utcnow().isoformat()
|
68 |
+
completion_json["history"] = history
|
69 |
+
completion_json["history_len"] = len(history)
|
70 |
|
71 |
try:
|
72 |
cfg.mongo_db[collection].insert_one(completion_json)
|
|
|
161 |
|
162 |
def get_answer(history, sources: Optional[list[str]] = None):
|
163 |
user_input = history[-1][0]
|
|
|
164 |
if len(sources) == 0:
|
165 |
completion = get_empty_source_completion(user_input)
|
166 |
|
|
|
176 |
|
177 |
for token in completion.answer_generator:
|
178 |
history[-1][1] += token
|
|
|
179 |
yield history, completion
|
180 |
|
181 |
|
|
|
204 |
)
|
205 |
|
206 |
chatbot = gr.Chatbot(elem_id="chatbot", show_copy_button=True)
|
|
|
207 |
with gr.Row():
|
208 |
question = gr.Textbox(
|
209 |
label="What's your question?",
|
|
|
236 |
submit.click(user, [question, chatbot], [question, chatbot], queue=False).then(
|
237 |
get_answer, inputs=[chatbot, source_selection], outputs=[chatbot, completion]
|
238 |
).then(add_sources, inputs=[chatbot, completion], outputs=[chatbot]).then(
|
239 |
+
save_completion, inputs=[completion, chatbot]
|
240 |
)
|
241 |
|
242 |
question.submit(user, [question, chatbot], [question, chatbot], queue=False).then(
|
243 |
get_answer, inputs=[chatbot, source_selection], outputs=[chatbot, completion]
|
244 |
).then(add_sources, inputs=[chatbot, completion], outputs=[chatbot]).then(
|
245 |
+
save_completion, inputs=[completion, chatbot]
|
246 |
)
|
247 |
|
248 |
chatbot.like(log_likes, completion)
|