Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,21 +22,24 @@ def chatbot(input_text, mentioned_person='Mediator John Haynes'):
|
|
| 22 |
response = index.query(prompt, response_mode="compact")
|
| 23 |
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
|
|
|
| 40 |
return response.response
|
| 41 |
|
| 42 |
|
|
|
|
| 22 |
response = index.query(prompt, response_mode="compact")
|
| 23 |
|
| 24 |
|
| 25 |
+
# code to save chat log to file
|
| 26 |
+
directory_path = "/chat"
|
| 27 |
+
filename = "chat_history.txt"
|
| 28 |
+
file_path = os.path.join(directory_path, filename)
|
| 29 |
+
|
| 30 |
+
current_time = datetime.datetime.now()
|
| 31 |
+
current_time_str = current_time.strftime("%Y-%m-%d_%H-%M-%S")
|
| 32 |
+
chat_log_filename = "chat_history.txt"
|
| 33 |
+
chat_log_dir = "chat" # replace with your desired directory name
|
| 34 |
+
if not os.path.exists(chat_log_dir):
|
| 35 |
+
os.makedirs(chat_log_dir)
|
| 36 |
+
chat_log_filepath = os.path.join(chat_log_dir, chat_log_filename)
|
| 37 |
+
with open(chat_log_filepath, "a") as f:
|
| 38 |
+
f.write(f"Chat at {current_time_str}\n")
|
| 39 |
+
f.write(f"User: {input_text}\n")
|
| 40 |
+
f.write(f"Chatbot: {response.response}\n\n")
|
| 41 |
|
| 42 |
+
# return the response
|
| 43 |
return response.response
|
| 44 |
|
| 45 |
|