Skip to content

Commit

Permalink
bugfix(ChatExcel): Tongyi proxyllm response with 'InvalidParameter:Us…
Browse files Browse the repository at this point in the history
…er and assistant need to appear alternately in the message' (#781)

Try to fix #756
  • Loading branch information
yhjun1026 committed Nov 6, 2023
2 parents 84054a4 + 352867d commit 47b1d0d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pilot/model/proxy/llms/tongyi.py
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

0 comments on commit 47b1d0d

Please sign in to comment.