quick fix history
Browse files- app/message_processor.py +11 -2
app/message_processor.py
CHANGED
|
@@ -168,10 +168,19 @@ class MessageProcessor:
|
|
| 168 |
|
| 169 |
for row in reversed(sorted_history):
|
| 170 |
temp_blocks = []
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
temp_total = sum(len(block['content']) for block in temp_blocks)
|
| 174 |
if total_chars + temp_total > MAX_CONTEXT_CHARS: continue
|
|
|
|
|
|
|
| 175 |
conversation_context = temp_blocks + conversation_context
|
| 176 |
total_chars += temp_total
|
| 177 |
|
|
|
|
| 168 |
|
| 169 |
for row in reversed(sorted_history):
|
| 170 |
temp_blocks = []
|
| 171 |
+
|
| 172 |
+
# --- SỬA LỖI THỨ TỰ LỊCH SỬ TẠI ĐÂY ---
|
| 173 |
+
# Đảm bảo lượt nói của user luôn được thêm vào trước.
|
| 174 |
+
if row.get('originaltext'):
|
| 175 |
+
temp_blocks.append({"role": "user", "content": row['originaltext']})
|
| 176 |
+
# Lượt nói của trợ lý ảo được thêm vào sau.
|
| 177 |
+
if row.get('systemresponse'):
|
| 178 |
+
temp_blocks.append({"role": "assistant", "content": row['systemresponse']})
|
| 179 |
+
|
| 180 |
temp_total = sum(len(block['content']) for block in temp_blocks)
|
| 181 |
if total_chars + temp_total > MAX_CONTEXT_CHARS: continue
|
| 182 |
+
|
| 183 |
+
# Thêm cặp hỏi-đáp vào đầu danh sách context, duy trì thứ tự thời gian
|
| 184 |
conversation_context = temp_blocks + conversation_context
|
| 185 |
total_chars += temp_total
|
| 186 |
|