@@ -97,8 +97,9 @@ conversationHistory[lastMessageIndex] is ChatMessage lastMessage &&
97
97
/// <remarks>
98
98
/// <para>
99
99
/// This function only considers the <see cref="ChatMessage.Text"/> and ignores any <see cref="AIContent"/>s
100
- /// present within the <see cref="ChatMessage.Contents"/> of the <paramref name="message"/> that are not
101
- /// <see cref="TextContent"/>s.
100
+ /// (present within the <see cref="ChatMessage.Contents"/> of the <paramref name="message"/>) that are not
101
+ /// <see cref="TextContent"/>s. If the <paramref name="message"/> does not contain any <see cref="TextContent"/>s
102
+ /// then this function returns an empty string.
102
103
/// </para>
103
104
/// <para>
104
105
/// The returned string is prefixed with the <see cref="ChatMessage.Role"/> and
@@ -112,6 +113,12 @@ public static string RenderText(this ChatMessage message)
112
113
{
113
114
_ = Throw . IfNull ( message ) ;
114
115
116
+ if ( ! message . Contents . OfType < TextContent > ( ) . Any ( ) )
117
+ {
118
+ // Don't render messages (such as messages with role ChatRole.Tool) that don't contain any textual content.
119
+ return string . Empty ;
120
+ }
121
+
115
122
string ? author = message . AuthorName ;
116
123
string role = message . Role . Value ;
117
124
string ? content = message . Text ;
@@ -129,8 +136,10 @@ public static string RenderText(this ChatMessage message)
129
136
/// <remarks>
130
137
/// <para>
131
138
/// This function only considers the <see cref="ChatMessage.Text"/> and ignores any <see cref="AIContent"/>s
132
- /// present within the <see cref="ChatMessage.Contents"/> of the <paramref name="messages"/> that are not
133
- /// <see cref="TextContent"/>s.
139
+ /// (present within the <see cref="ChatMessage.Contents"/> of the <paramref name="messages"/>) that are not
140
+ /// <see cref="TextContent"/>s. Any <paramref name="messages"/> that contain no <see cref="TextContent"/>s will be
141
+ /// skipped and will not be rendered. If none of the <paramref name="messages"/> include any
142
+ /// <see cref="TextContent"/>s then this function will return an empty string.
134
143
/// </para>
135
144
/// <para>
136
145
/// The rendered <paramref name="messages"/> are each prefixed with the <see cref="ChatMessage.Role"/> and
0 commit comments