MZhaovo commited on
Commit
6582601
·
1 Parent(s): 73da7f9

fix: 使用self.history实现自动命名

Browse files
modules/models/base_model.py CHANGED
@@ -680,8 +680,8 @@ class BaseLLMModel:
680
  return init_history_list(user_name)
681
 
682
  def auto_name_chat_history(self, name_chat_method, user_question, chatbot, user_name, language):
683
- if len(chatbot) == 1:
684
- user_question = chatbot[0][0][26:-6]
685
  filename = user_question[:16] + ".json"
686
  return self.rename_chat_history(filename, chatbot, user_name)
687
  else:
 
680
  return init_history_list(user_name)
681
 
682
  def auto_name_chat_history(self, name_chat_method, user_question, chatbot, user_name, language):
683
+ if len(self.history) == 2:
684
+ user_question = self.history[0]["content"]
685
  filename = user_question[:16] + ".json"
686
  return self.rename_chat_history(filename, chatbot, user_name)
687
  else:
modules/models/models.py CHANGED
@@ -257,17 +257,13 @@ class OpenAIClient(BaseLLMModel):
257
 
258
 
259
  def auto_name_chat_history(self, name_chat_method, user_question, chatbot, user_name, language):
260
- if len(chatbot) == 1:
261
- # 用户问题示例”<div class="user-message">你好呀</div>“
262
- user_question = chatbot[0][0][26:-6]
263
  if name_chat_method == i18n("模型自动总结(消耗tokens)"):
264
- # ai回答示例”<div class="raw-message hideM"><pre>你好!有什么我可以帮助你的吗?</pre></div><div class="md-message">\n\n你好!有什么我可以帮助你的吗?\n</div>“
265
- pattern = r'<div class="raw-message hideM"><pre>(.*?)</pre></div><div class="md-message">'
266
- match = re.search(pattern, chatbot[0][1])
267
- ai_answer = match.group(1)
268
  try:
269
  history = [
270
- { "role": "system", "content": f"Please summarize the following conversation for a chat topic.\nNo more than 16 characters.\nNo special characters.\nReply in user's language."},
271
  { "role": "user", "content": f"User: {user_question}\nAssistant: {ai_answer}"}
272
  ]
273
  response = self._single_query_at_once(history, temperature=0.0)
 
257
 
258
 
259
  def auto_name_chat_history(self, name_chat_method, user_question, chatbot, user_name, language):
260
+ if len(self.history) == 2:
261
+ user_question = self.history[0]["content"]
 
262
  if name_chat_method == i18n("模型自动总结(消耗tokens)"):
263
+ ai_answer = self.history[1]["content"]
 
 
 
264
  try:
265
  history = [
266
+ { "role": "system", "content": SUMMARY_CHAT_SYSTEM_PROMPT},
267
  { "role": "user", "content": f"User: {user_question}\nAssistant: {ai_answer}"}
268
  ]
269
  response = self._single_query_at_once(history, temperature=0.0)
modules/presets.py CHANGED
@@ -184,6 +184,15 @@ SUMMARIZE_PROMPT = """Write a concise summary of the following:
184
 
185
  CONCISE SUMMARY IN 中文:"""
186
 
 
 
 
 
 
 
 
 
 
187
  ALREADY_CONVERTED_MARK = "<!-- ALREADY CONVERTED BY PARSER. -->"
188
  START_OF_OUTPUT_MARK = "<!-- SOO IN MESSAGE -->"
189
  END_OF_OUTPUT_MARK = "<!-- EOO IN MESSAGE -->"
 
184
 
185
  CONCISE SUMMARY IN 中文:"""
186
 
187
+ SUMMARY_CHAT_SYSTEM_PROMPT = """\
188
+ Please summarize the following conversation for a chat topic.
189
+ No more than 16 characters.
190
+ No special characters.
191
+ Punctuation mark is banned.
192
+ Not including '.' ':' '?' '!' '“' '*' '<' '>'.
193
+ Reply in user's language.
194
+ """
195
+
196
  ALREADY_CONVERTED_MARK = "<!-- ALREADY CONVERTED BY PARSER. -->"
197
  START_OF_OUTPUT_MARK = "<!-- SOO IN MESSAGE -->"
198
  END_OF_OUTPUT_MARK = "<!-- EOO IN MESSAGE -->"