Anne31415 commited on
Commit
51c6da7
·
verified ·
1 Parent(s): 75835ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -179,8 +179,15 @@ def ask_bot(query):
179
  return
180
 
181
  def save_conversation(chat_history, session_id):
 
 
 
 
 
 
 
182
  # Create a unique filename using session_id
183
- filename = f"conversation_logs/{session_id}.json"
184
 
185
  # Save the chat history as JSON
186
  with open(filename, 'w') as file:
@@ -188,11 +195,19 @@ def save_conversation(chat_history, session_id):
188
 
189
  # Git operations to push the file
190
  try:
 
 
 
 
191
  repo.git_add(filename)
192
  repo.git_commit(f"Add conversation log for session {session_id}")
193
  repo.git_push()
 
 
 
194
  except Exception as e:
195
  print(f"Error during Git operations: {e}")
 
196
 
197
 
198
  def page1():
 
179
  return
180
 
181
  def save_conversation(chat_history, session_id):
182
+ # Define the base path for conversation logs
183
+ base_path = "Private_Book/conversation_logs"
184
+
185
+ # Create the directory if it doesn't exist
186
+ if not os.path.exists(base_path):
187
+ os.makedirs(base_path)
188
+
189
  # Create a unique filename using session_id
190
+ filename = f"{base_path}/{session_id}.json"
191
 
192
  # Save the chat history as JSON
193
  with open(filename, 'w') as file:
 
195
 
196
  # Git operations to push the file
197
  try:
198
+ # Change directory to Private_Book for Git operations
199
+ original_dir = os.getcwd()
200
+ os.chdir('Private_Book')
201
+
202
  repo.git_add(filename)
203
  repo.git_commit(f"Add conversation log for session {session_id}")
204
  repo.git_push()
205
+
206
+ # Change back to the original directory
207
+ os.chdir(original_dir)
208
  except Exception as e:
209
  print(f"Error during Git operations: {e}")
210
+
211
 
212
 
213
  def page1():