lmzjms commited on
Commit
965f6fd
·
1 Parent(s): fe9952a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -187,18 +187,20 @@ New input: {input}
187
  Thought: Do I need to use a tool? {agent_scratchpad}"""
188
 
189
  def cut_dialogue_history(history_memory, keep_last_n_words = 500):
 
 
 
190
  tokens = history_memory.split()
191
  n_tokens = len(tokens)
192
  print(f"history_memory:{history_memory}, n_tokens: {n_tokens}")
193
  if n_tokens < keep_last_n_words:
194
  return history_memory
195
- else:
196
- paragraphs = history_memory.split('\n')
197
- last_n_tokens = n_tokens
198
- while last_n_tokens >= keep_last_n_words:
199
- last_n_tokens = last_n_tokens - len(paragraphs[0].split(' '))
200
- paragraphs = paragraphs[1:]
201
- return '\n' + '\n'.join(paragraphs)
202
 
203
 
204
 
 
187
  Thought: Do I need to use a tool? {agent_scratchpad}"""
188
 
189
  def cut_dialogue_history(history_memory, keep_last_n_words = 500):
190
+ if history_memory is None or len(history_memory) == 0:
191
+ print("history memory is none.")
192
+ return history_memory
193
  tokens = history_memory.split()
194
  n_tokens = len(tokens)
195
  print(f"history_memory:{history_memory}, n_tokens: {n_tokens}")
196
  if n_tokens < keep_last_n_words:
197
  return history_memory
198
+ paragraphs = history_memory.split('\n')
199
+ last_n_tokens = n_tokens
200
+ while last_n_tokens >= keep_last_n_words:
201
+ last_n_tokens -= len(paragraphs[0].split(' '))
202
+ paragraphs = paragraphs[1:]
203
+ return '\n' + '\n'.join(paragraphs)
 
204
 
205
 
206