-
Notifications
You must be signed in to change notification settings - Fork 763
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a few issues in IChatClient implementations (#5549)
* Fix a few issues in IChatClient implementations - Avoid null arg exception when constructing system message with null text - Avoid empty exception when constructing user message with no parts - Use all parts rather than just first text part for system message - Handle assistant messages with both content and tools - Avoid unnecessarily trying to weed out duplicate call ids * Address PR feedback - Normalize null to string.Empty in TextContent - Ensure GetContentParts always produces at least one part, even if empty text content
- Loading branch information
1 parent
2dd959f
commit 7cac12b
Showing
7 changed files
with
510 additions
and
64 deletions.
There are no files selected for viewing
15 changes: 12 additions & 3 deletions
15
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/TextContent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary> | ||
/// Represents text content in a chat. | ||
/// </summary> | ||
public sealed class TextContent : AIContent | ||
{ | ||
private string? _text; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TextContent"/> class. | ||
/// </summary> | ||
/// <param name="text">The text content.</param> | ||
public TextContent(string? text) | ||
{ | ||
Text = text; | ||
_text = text; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the text content. | ||
/// </summary> | ||
public string? Text { get; set; } | ||
[AllowNull] | ||
public string Text | ||
{ | ||
get => _text ?? string.Empty; | ||
set => _text = value; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() => Text ?? string.Empty; | ||
public override string ToString() => Text; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.