Skip to content
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: 16 additions & 1 deletion Anthropic.SDK/Messaging/ChatClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,20 @@ public static MessageParameters CreateMessageParameters(IChatClient client, IEnu
break;

case Microsoft.Extensions.AI.TextContent textContent:
currentMessage.Content.Add(new TextContent() { Text = textContent.Text });
string text = textContent.Text;
if (currentMessage.Role == RoleType.Assistant)
{
text.TrimEnd();
if (text.Length != 0)
{
currentMessage.Content.Add(new TextContent() { Text = text });
}
}
else
{
currentMessage.Content.Add(new TextContent() { Text = text });
}

break;

case Microsoft.Extensions.AI.DataContent imageContent when imageContent.HasTopLevelMediaType("image"):
Expand Down Expand Up @@ -224,6 +237,8 @@ public static MessageParameters CreateMessageParameters(IChatClient client, IEnu
}
}

parameters.Messages.RemoveAll(m => m.Content.Count == 0);

return parameters;
}

Expand Down
Loading