cafierom commited on
Commit
10dc7f1
·
verified ·
1 Parent(s): aa5f138

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -13
app.py CHANGED
@@ -125,7 +125,8 @@ class chat_manager():
125
 
126
  top_hits, search_string, _ = websearch_node(query, self.embed_model)
127
  local_chat_history.append(search_string)
128
- self.chat_history.append(local_chat_history)
 
129
  with open('chat_session_history.txt', 'w') as f:
130
  pp.pp(self.chat_history, stream=f)
131
 
@@ -180,7 +181,8 @@ manual mode. Reference the previous conversation in the context if needed."
180
  response = parts[1].strip('\n').strip('<end_of_turn>')
181
  self.latest_response = response
182
  local_chat_history.append(response)
183
- self.chat_history.append(local_chat_history)
 
184
  with open('chat_session_history.txt', 'w') as f:
185
  pp.pp(self.chat_history, stream=f)
186
 
@@ -221,7 +223,8 @@ manual mode. Reference the previous conversation in the context if needed."
221
  response = response.replace(m, f'```{m}```')
222
 
223
  local_chat_history.append(response)
224
- self.chat_history.append(local_chat_history)
 
225
  with open('chat_session_history.txt', 'w') as f:
226
  pp.pp(self.chat_history, stream=f)
227
 
@@ -248,7 +251,8 @@ manual mode. Reference the previous conversation in the context if needed."
248
  response += f'**{i+1}**. {list_name}\n'
249
 
250
  local_chat_history.append(response)
251
- self.chat_history.append(local_chat_history)
 
252
  with open('chat_session_history.txt', 'w') as f:
253
  pp.pp(self.chat_history, stream=f)
254
  return '', self.chat_history, None
@@ -264,7 +268,8 @@ manual mode. Reference the previous conversation in the context if needed."
264
  response = 'Invalid input. Please enter 1, 2, or 3 to choose one of the tools above, or hit enter to accept the #1 tool choice. \
265
  or enter "edit" to edit a list.'
266
  local_chat_history.append(response)
267
- self.chat_history.append(local_chat_history)
 
268
  with open('chat_session_history.txt', 'w') as f:
269
  pp.pp(self.chat_history, stream=f)
270
 
@@ -289,7 +294,8 @@ or enter "edit" to edit a list.'
289
  data_request += 'Please provide the necessary information to proceed.'
290
  if missing_data:
291
  local_chat_history.append(data_request)
292
- self.chat_history.append(local_chat_history)
 
293
  with open('chat_session_history.txt', 'w') as f:
294
  pp.pp(self.chat_history, stream=f)
295
  self.chat_idx = 999
@@ -320,7 +326,8 @@ or enter "edit" to edit a list.'
320
  self.results_string = self.results_string.replace(m, f'```{m}```')
321
 
322
  local_chat_history.append(self.results_string)
323
- self.chat_history.append(local_chat_history)
 
324
  with open('chat_session_history.txt', 'w') as f:
325
  pp.pp(self.chat_history, stream=f)
326
  try:
@@ -371,7 +378,8 @@ or enriching information where appropriate."
371
  response = response.replace(m, f'```{m}```')
372
 
373
  local_chat_history.append(response)
374
- self.chat_history.append(local_chat_history)
 
375
  with open('chat_session_history.txt', 'w') as f:
376
  pp.pp(self.chat_history, stream=f)
377
  self.chat_idx += 1
@@ -437,7 +445,8 @@ or enriching information where appropriate."
437
  response = response.replace(m, f'```{m}```')
438
 
439
  local_chat_history.append(response)
440
- self.chat_history.append(local_chat_history)
 
441
  with open('chat_session_history.txt', 'w') as f:
442
  pp.pp(self.chat_history, stream=f)
443
 
@@ -493,7 +502,8 @@ or enriching information where appropriate."
493
  response = response.replace(m, f'```{m}```')
494
 
495
  local_chat_history.append(response)
496
- self.chat_history.append(local_chat_history)
 
497
  with open('chat_session_history.txt', 'w') as f:
498
  pp.pp(self.chat_history, stream=f)
499
 
@@ -520,7 +530,8 @@ or enriching information where appropriate."
520
  self.chat_idx = 501
521
 
522
  local_chat_history.append(response)
523
- self.chat_history.append(local_chat_history)
 
524
  with open('chat_session_history.txt', 'w') as f:
525
  pp.pp(self.chat_history, stream=f)
526
  return '', self.chat_history, None
@@ -545,7 +556,8 @@ or enriching information where appropriate."
545
  response = 'Invalid input. Please enter the numbers corresponding to the items you wish to keep.'
546
  self.chat_idx = 502
547
  local_chat_history.append(response)
548
- self.chat_history.append(local_chat_history)
 
549
  with open('chat_session_history.txt', 'w') as f:
550
  pp.pp(self.chat_history, stream=f)
551
  return '', self.chat_history, None
@@ -616,7 +628,8 @@ or enriching information where appropriate."
616
  self.chat_idx = 502
617
 
618
  local_chat_history.append(response)
619
- self.chat_history.append(local_chat_history)
 
620
  with open('chat_session_history.txt', 'w') as f:
621
  pp.pp(self.chat_history, stream=f)
622
 
 
125
 
126
  top_hits, search_string, _ = websearch_node(query, self.embed_model)
127
  local_chat_history.append(search_string)
128
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
129
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
130
  with open('chat_session_history.txt', 'w') as f:
131
  pp.pp(self.chat_history, stream=f)
132
 
 
181
  response = parts[1].strip('\n').strip('<end_of_turn>')
182
  self.latest_response = response
183
  local_chat_history.append(response)
184
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
185
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
186
  with open('chat_session_history.txt', 'w') as f:
187
  pp.pp(self.chat_history, stream=f)
188
 
 
223
  response = response.replace(m, f'```{m}```')
224
 
225
  local_chat_history.append(response)
226
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
227
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
228
  with open('chat_session_history.txt', 'w') as f:
229
  pp.pp(self.chat_history, stream=f)
230
 
 
251
  response += f'**{i+1}**. {list_name}\n'
252
 
253
  local_chat_history.append(response)
254
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
255
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
256
  with open('chat_session_history.txt', 'w') as f:
257
  pp.pp(self.chat_history, stream=f)
258
  return '', self.chat_history, None
 
268
  response = 'Invalid input. Please enter 1, 2, or 3 to choose one of the tools above, or hit enter to accept the #1 tool choice. \
269
  or enter "edit" to edit a list.'
270
  local_chat_history.append(response)
271
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
272
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
273
  with open('chat_session_history.txt', 'w') as f:
274
  pp.pp(self.chat_history, stream=f)
275
 
 
294
  data_request += 'Please provide the necessary information to proceed.'
295
  if missing_data:
296
  local_chat_history.append(data_request)
297
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
298
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
299
  with open('chat_session_history.txt', 'w') as f:
300
  pp.pp(self.chat_history, stream=f)
301
  self.chat_idx = 999
 
326
  self.results_string = self.results_string.replace(m, f'```{m}```')
327
 
328
  local_chat_history.append(self.results_string)
329
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
330
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
331
  with open('chat_session_history.txt', 'w') as f:
332
  pp.pp(self.chat_history, stream=f)
333
  try:
 
378
  response = response.replace(m, f'```{m}```')
379
 
380
  local_chat_history.append(response)
381
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
382
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
383
  with open('chat_session_history.txt', 'w') as f:
384
  pp.pp(self.chat_history, stream=f)
385
  self.chat_idx += 1
 
445
  response = response.replace(m, f'```{m}```')
446
 
447
  local_chat_history.append(response)
448
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
449
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
450
  with open('chat_session_history.txt', 'w') as f:
451
  pp.pp(self.chat_history, stream=f)
452
 
 
502
  response = response.replace(m, f'```{m}```')
503
 
504
  local_chat_history.append(response)
505
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
506
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
507
  with open('chat_session_history.txt', 'w') as f:
508
  pp.pp(self.chat_history, stream=f)
509
 
 
530
  self.chat_idx = 501
531
 
532
  local_chat_history.append(response)
533
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
534
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
535
  with open('chat_session_history.txt', 'w') as f:
536
  pp.pp(self.chat_history, stream=f)
537
  return '', self.chat_history, None
 
556
  response = 'Invalid input. Please enter the numbers corresponding to the items you wish to keep.'
557
  self.chat_idx = 502
558
  local_chat_history.append(response)
559
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
560
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
561
  with open('chat_session_history.txt', 'w') as f:
562
  pp.pp(self.chat_history, stream=f)
563
  return '', self.chat_history, None
 
628
  self.chat_idx = 502
629
 
630
  local_chat_history.append(response)
631
+ self.chat_history.append({'role': 'user', 'content': local_chat_history[0]})
632
+ self.chat_history.append({'role': 'assistant', 'content': local_chat_history[1]})
633
  with open('chat_session_history.txt', 'w') as f:
634
  pp.pp(self.chat_history, stream=f)
635