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/model/proxy/llms/bard.py Normal file → Executable file
View File

@@ -25,14 +25,13 @@ def bard_generate_stream(
else:
pass
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)
msgs = []

13
dbgpt/model/proxy/llms/chatgpt.py Normal file → Executable file
View File

@@ -110,14 +110,13 @@ def _build_request(model: ProxyModel, params):
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)
payloads = {