yangapku commited on
Commit
98a5dbc
1 Parent(s): 806d62b

update modeling.py

Browse files
Files changed (1) hide show
  1. modeling_qwen.py +10 -3
modeling_qwen.py CHANGED
@@ -3,6 +3,7 @@
3
  # This source code is licensed under the license found in the
4
  # LICENSE file in the root directory of this source tree.
5
 
 
6
  import importlib
7
  import math
8
  from typing import TYPE_CHECKING, Optional, Tuple, Union, Callable, List, Any, Generator
@@ -1177,7 +1178,6 @@ class QWenLMHeadModel(QWenPreTrainedModel):
1177
  query: str,
1178
  history: Optional[HistoryType],
1179
  system: str = "You are a helpful assistant.",
1180
- append_history: bool = True,
1181
  stream: Optional[bool] = _SENTINEL,
1182
  stop_words_ids: Optional[List[List[int]]] = None,
1183
  generation_config: Optional[GenerationConfig] = None,
@@ -1189,6 +1189,10 @@ class QWenLMHeadModel(QWenPreTrainedModel):
1189
  assert generation_config.chat_format == 'chatml', _ERROR_BAD_CHAT_FORMAT
1190
  if history is None:
1191
  history = []
 
 
 
 
1192
  if stop_words_ids is None:
1193
  stop_words_ids = []
1194
 
@@ -1226,8 +1230,11 @@ class QWenLMHeadModel(QWenPreTrainedModel):
1226
  errors='replace'
1227
  )
1228
 
1229
- if append_history:
1230
- history.append((query, response))
 
 
 
1231
 
1232
  return response, history
1233
 
 
3
  # This source code is licensed under the license found in the
4
  # LICENSE file in the root directory of this source tree.
5
 
6
+ import copy
7
  import importlib
8
  import math
9
  from typing import TYPE_CHECKING, Optional, Tuple, Union, Callable, List, Any, Generator
 
1178
  query: str,
1179
  history: Optional[HistoryType],
1180
  system: str = "You are a helpful assistant.",
 
1181
  stream: Optional[bool] = _SENTINEL,
1182
  stop_words_ids: Optional[List[List[int]]] = None,
1183
  generation_config: Optional[GenerationConfig] = None,
 
1189
  assert generation_config.chat_format == 'chatml', _ERROR_BAD_CHAT_FORMAT
1190
  if history is None:
1191
  history = []
1192
+ else:
1193
+ # make a copy of the user's input such that is is left untouched
1194
+ history = copy.deepcopy(history)
1195
+
1196
  if stop_words_ids is None:
1197
  stop_words_ids = []
1198
 
 
1230
  errors='replace'
1231
  )
1232
 
1233
+ # as history is a copy of the user inputs,
1234
+ # we can always return the new turn to the user.
1235
+ # separating input history and output history also enables the user
1236
+ # to implement more complex history management
1237
+ history.append((query, response))
1238
 
1239
  return response, history
1240