fix(core): Move the last user's information to the end (#960)

This commit is contained in:
vvycaaa
2023-12-22 09:42:58 +08:00
committed by GitHub
parent 6b982e2879
commit d9065227bd
4 changed files with 75 additions and 21 deletions

13
dbgpt/core/interface/message.py Normal file → Executable file
View File

@@ -157,14 +157,13 @@ class ModelMessage(BaseModel):
else:
pass
# Move the last user's information to the end
temp_his = history[::-1]
last_user_input = None
for m in temp_his:
if m["role"] == "user":
last_user_input = m
last_user_input_index = None
for i in range(len(history) - 1, -1, -1):
if history[i]["role"] == "user":
last_user_input_index = i
break
if last_user_input:
history.remove(last_user_input)
if last_user_input_index:
last_user_input = history.pop(last_user_input_index)
history.append(last_user_input)
return history