1- using System . Diagnostics . CodeAnalysis ;
1+ using Liquid . Core . GenAi . Enums ;
2+ using System ;
3+ using System . Collections . Generic ;
4+ using System . Diagnostics . CodeAnalysis ;
25
36namespace Liquid . Core . GenAi . Entities
47{
@@ -11,11 +14,80 @@ public class LiquidChatMessage
1114 /// <summary>
1215 /// The chat role associated with this message.
1316 /// </summary>
14- public string Role { get ; set ; }
17+ public LiquidMessageRole Role { get ; set ; }
18+
19+ /// <summary>
20+ /// Initializes a new instance of the <see cref="LiquidChatMessage"/> class with the specified role.
21+ /// </summary>
22+ /// <param name="role">The role associated with the chat message. This value cannot be null or empty.</param>
23+ public LiquidChatMessage ( LiquidMessageRole role )
24+ {
25+ Role = role ;
26+ }
1527
1628 /// <summary>
1729 /// The contents of the message.
1830 /// </summary>
19- public LiquidChatContent [ ] Content { get ; set ; }
31+ public LiquidChatContent [ ] Content { get ; set ; } = Array . Empty < LiquidChatContent > ( ) ;
32+
33+
34+ /// <summary>
35+ /// Adds a text content item to the current collection of chat contents.
36+ /// </summary>
37+ /// <remarks>This method appends the specified text as a new content item to the existing
38+ /// collection. If the collection is initially null, it initializes the collection with the new content
39+ /// item.</remarks>
40+ /// <param name="text">The text content to add. Cannot be null, empty, or consist solely of whitespace.</param>
41+ /// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is null, empty, or consists only of whitespace.</exception>
42+ public void AddContent ( string text )
43+ {
44+ if ( string . IsNullOrWhiteSpace ( text ) )
45+ {
46+ throw new ArgumentException ( "Text content cannot be null or empty." , nameof ( text ) ) ;
47+ }
48+ var content = new LiquidChatContent
49+ {
50+ Kind = LiquidContentKind . Text ,
51+ Text = text
52+ } ;
53+ if ( Content == null )
54+ {
55+ Content = new [ ] { content } ;
56+ }
57+ else
58+ {
59+ var contentList = new List < LiquidChatContent > ( Content ) { content } ;
60+ Content = contentList . ToArray ( ) ;
61+ }
62+ }
63+
64+ /// <summary>
65+ /// Adds an image content to the current collection of chat contents.
66+ /// </summary>
67+ /// <remarks>If the content collection is initially empty, this method initializes it with the new
68+ /// image content. Otherwise, it appends the image content to the existing collection.</remarks>
69+ /// <param name="imageUri">The URI of the image to be added. Cannot be <see langword="null"/>.</param>
70+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="imageUri"/> is <see langword="null"/>.</exception>
71+ public void AddContent ( Uri imageUri )
72+ {
73+ if ( imageUri == null )
74+ {
75+ throw new ArgumentNullException ( nameof ( imageUri ) , "Image URI cannot be null." ) ;
76+ }
77+ var content = new LiquidChatContent
78+ {
79+ Kind = LiquidContentKind . Image ,
80+ ImageUri = imageUri
81+ } ;
82+ if ( Content == null )
83+ {
84+ Content = new [ ] { content } ;
85+ }
86+ else
87+ {
88+ var contentList = new List < LiquidChatContent > ( Content ) { content } ;
89+ Content = contentList . ToArray ( ) ;
90+ }
91+ }
2092 }
2193}
0 commit comments