Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix(ChatExcel): Tongyi proxyllm response with 'InvalidParameter:User and assistant need to appear alternately in the message' #781

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pilot/model/proxy/llms/tongyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def tongyi_generate_stream(
if message.role == ModelMessageRoleType.HUMAN:
history.append({"role": "user", "content": message.content})
for message in messages:
if message.role == ModelMessageRoleType.SYSTEM:
if message.role == ModelMessageRoleType.SYSTEM or message.role == ModelMessageRoleType.HUMAN:
history.append({"role": "user", "content": message.content})
# elif message.role == ModelMessageRoleType.HUMAN:
# history.append({"role": "user", "content": message.content})
Expand All @@ -45,17 +45,24 @@ def tongyi_generate_stream(
else:
pass

# temp_his = history[::-1]
temp_his = history
temp_his = history[::-1]
last_user_input = None
for m in temp_his:
if m["role"] == "user":
last_user_input = m
break

if last_user_input:
temp_his = history
prompt_input = None
for m in temp_his:
if m["role"] == "user":
prompt_input = m
break

if last_user_input and prompt_input and last_user_input != prompt_input:
history.remove(last_user_input)
history.append(last_user_input)
history.remove(prompt_input)
history.append(prompt_input)

gen = Generation()
res = gen.call(
Expand Down