@@ -9,12 +9,14 @@ namespace Cnblogs.DashScope.Core;
99/// <param name="Role">The role of this message.</param>
1010/// <param name="Content">The content of this message.</param>
1111/// <param name="Name">Used when role is tool, represents the function name of this message generated by.</param>
12+ /// <param name="Partial">Notify model that next message should use this message as prefix.</param>
1213/// <param name="ToolCalls">Calls to the function.</param>
1314[ method: JsonConstructor ]
1415public record ChatMessage (
1516 string Role ,
1617 string Content ,
1718 string ? Name = null ,
19+ bool ? Partial = null ,
1820 List < ToolCall > ? ToolCalls = null ) : IMessage < string >
1921{
2022 /// <summary>
@@ -34,4 +36,69 @@ public ChatMessage(IEnumerable<DashScopeFileId> fileIds)
3436 : this ( "system" , string . Join ( ',' , fileIds . Select ( f => f . ToUrl ( ) ) ) )
3537 {
3638 }
39+
40+ /// <summary>
41+ /// Creates a file message.
42+ /// </summary>
43+ /// <param name="fileId">The id of the file.</param>
44+ /// <returns></returns>
45+ public static ChatMessage File ( DashScopeFileId fileId )
46+ {
47+ return new ChatMessage ( fileId ) ;
48+ }
49+
50+ /// <summary>
51+ /// Creates a file message.
52+ /// </summary>
53+ /// <param name="fileIds">The file id list.</param>
54+ /// <returns></returns>
55+ public static ChatMessage File ( IEnumerable < DashScopeFileId > fileIds )
56+ {
57+ return new ChatMessage ( fileIds ) ;
58+ }
59+
60+ /// <summary>
61+ /// Create a user message.
62+ /// </summary>
63+ /// <param name="content">Content of the message.</param>
64+ /// <param name="name">Author name.</param>
65+ /// <returns></returns>
66+ public static ChatMessage User ( string content , string ? name = null )
67+ {
68+ return new ChatMessage ( DashScopeRoleNames . User , content , name ) ;
69+ }
70+
71+ /// <summary>
72+ /// Create a system message.
73+ /// </summary>
74+ /// <param name="content">The content of the message.</param>
75+ /// <returns></returns>
76+ public static ChatMessage System ( string content )
77+ {
78+ return new ChatMessage ( DashScopeRoleNames . System , content ) ;
79+ }
80+
81+ /// <summary>
82+ /// Create an assistant message
83+ /// </summary>
84+ /// <param name="content">The content of the message.</param>
85+ /// <param name="partial">When set to true, content of this message would be the prefix of next model output.</param>
86+ /// <param name="name">Author name.</param>
87+ /// <param name="toolCalls">Tool calls by model.</param>
88+ /// <returns></returns>
89+ public static ChatMessage Assistant ( string content , bool ? partial = null , string ? name = null , List < ToolCall > ? toolCalls = null )
90+ {
91+ return new ChatMessage ( DashScopeRoleNames . Assistant , content , name , partial , toolCalls ) ;
92+ }
93+
94+ /// <summary>
95+ /// Create a tool message.
96+ /// </summary>
97+ /// <param name="content">The output from tool.</param>
98+ /// <param name="name">The name of the tool.</param>
99+ /// <returns></returns>
100+ public static ChatMessage Tool ( string content , string ? name = null )
101+ {
102+ return new ChatMessage ( DashScopeRoleNames . Tool , content , name ) ;
103+ }
37104}
0 commit comments