Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 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 |
|