Merge pull request #1703 from NousResearch/fix/anthropic-adapter-merge-content-loss
fix(anthropic): consecutive assistant message merge drops content on mixed types
This commit is contained in:
commit
75c5136e5a
1 changed files with 6 additions and 2 deletions
|
|
@ -963,8 +963,12 @@ def convert_messages_to_anthropic(
|
||||||
elif isinstance(prev_blocks, str) and isinstance(curr_blocks, str):
|
elif isinstance(prev_blocks, str) and isinstance(curr_blocks, str):
|
||||||
fixed[-1]["content"] = prev_blocks + "\n" + curr_blocks
|
fixed[-1]["content"] = prev_blocks + "\n" + curr_blocks
|
||||||
else:
|
else:
|
||||||
# Keep the later message
|
# Mixed types — normalize both to list and merge
|
||||||
fixed[-1] = m
|
if isinstance(prev_blocks, str):
|
||||||
|
prev_blocks = [{"type": "text", "text": prev_blocks}]
|
||||||
|
if isinstance(curr_blocks, str):
|
||||||
|
curr_blocks = [{"type": "text", "text": curr_blocks}]
|
||||||
|
fixed[-1]["content"] = prev_blocks + curr_blocks
|
||||||
else:
|
else:
|
||||||
fixed.append(m)
|
fixed.append(m)
|
||||||
result = fixed
|
result = fixed
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue