Skip to content

Commit

Permalink
bugfix: corrupted history may exceed token limit fix #916
Browse files Browse the repository at this point in the history
  • Loading branch information
GaiZhenbiao committed Oct 12, 2023
1 parent e99bd71 commit efd54c9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions ChuanhuChatbot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# -*- coding:utf-8 -*-
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] %(message)s",
)

from modules.models.models import get_model
from modules.train_func import *
from modules.repo import *
Expand All @@ -10,11 +16,6 @@
from modules import config
import gradio as gr
import colorama
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] %(message)s",
)


logging.getLogger("httpx").setLevel(logging.WARNING)
Expand Down
2 changes: 1 addition & 1 deletion modules/models/OpenAI.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def _decode_chat_response(self, response):
except:
print(f"ERROR: {chunk}")
continue
if error_msg:
if error_msg and not error_msg=="data: [DONE]":
raise Exception(error_msg)

def set_key(self, new_access_key):
Expand Down
4 changes: 4 additions & 0 deletions modules/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ def load_chat_history(self, new_history_file_path=None, username=None):
logging.info(new_history)
except:
pass
if len(json_s["chatbot"]) < len(json_s["history"]):
logging.info("Trimming corrupted history...")
json_s["history"] = json_s["history"][-len(json_s["chatbot"]):]
logging.info(f"Trimmed history: {json_s['history']}")
logging.debug(f"{self.user_identifier} 加载对话历史完毕")
self.history = json_s["history"]
return os.path.basename(self.history_file_path), json_s["system"], json_s["chatbot"]
Expand Down
3 changes: 0 additions & 3 deletions modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ def auto_name_chat_history(current_model, *args):
def export_markdown(current_model, *args):
return current_model.export_markdown(*args)

def load_chat_history(current_model, *args):
return current_model.load_chat_history(*args)

def upload_chat_history(current_model, *args):
return current_model.load_chat_history(*args)

Expand Down

0 comments on commit efd54c9

Please sign in to comment.