@@ -33,6 +33,7 @@ public async Task GenerateCommitMessage(string repo, string changeList, Action<s
3333 userMessageBuilder
3434 . AppendLine ( "Generate a commit message (follow the rule of conventional commit message) for given git repository." )
3535 . AppendLine ( "- Read all given changed files before generating. Do not skip any one file." )
36+ . AppendLine ( "- Output the conventional commit message (with detail changes in list) directly. Do not explain your output nor introduce your answer." )
3637 . AppendLine ( string . IsNullOrEmpty ( _ai . AdditionalPrompt ) ? string . Empty : _ai . AdditionalPrompt )
3738 . Append ( "Reposiory path: " ) . AppendLine ( repo . Quoted ( ) )
3839 . AppendLine ( "Changed files: " )
@@ -42,51 +43,38 @@ public async Task GenerateCommitMessage(string repo, string changeList, Action<s
4243
4344 do
4445 {
46+ ChatCompletion completion = await chatClient . CompleteChatAsync ( messages , options , cancellation ) ;
4547 var inProgress = false ;
46- var updates = chatClient . CompleteChatStreamingAsync ( messages , options ) . WithCancellation ( cancellation ) ;
47- var toolCalls = new ToolCallsBuilder ( ) ;
48- var contentBuilder = new StringBuilder ( ) ;
4948
50- await foreach ( var update in updates )
49+ switch ( completion . FinishReason )
5150 {
52- foreach ( var contentPart in update . ContentUpdate )
53- contentBuilder . Append ( contentPart . Text ) ;
51+ case ChatFinishReason . Stop :
52+ onUpdate ? . Invoke ( string . Empty ) ;
53+ onUpdate ? . Invoke ( "[Assistant]:" ) ;
54+ if ( completion . Content . Count > 0 )
55+ onUpdate ? . Invoke ( completion . Content [ 0 ] . Text ) ;
56+ else
57+ onUpdate ? . Invoke ( "[No content was generated.]" ) ;
58+ break ;
59+ case ChatFinishReason . Length :
60+ throw new Exception ( "The response was cut off because it reached the maximum length. Consider increasing the max tokens limit." ) ;
61+ case ChatFinishReason . ToolCalls :
62+ {
63+ messages . Add ( new AssistantChatMessage ( completion ) ) ;
5464
55- foreach ( var toolCall in update . ToolCallUpdates )
56- toolCalls . Append ( toolCall ) ;
57-
58- switch ( update . FinishReason )
59- {
60- case ChatFinishReason . Stop :
61- onUpdate ? . Invoke ( string . Empty ) ;
62- onUpdate ? . Invoke ( "[Assistant]:" ) ;
63- onUpdate ? . Invoke ( contentBuilder . ToString ( ) ) ;
64- break ;
65- case ChatFinishReason . Length :
66- throw new Exception ( "The response was cut off because it reached the maximum length. Consider increasing the max tokens limit." ) ;
67- case ChatFinishReason . ToolCalls :
65+ foreach ( var call in completion . ToolCalls )
6866 {
69- var calls = toolCalls . Build ( ) ;
70- var assistantMessage = new AssistantChatMessage ( calls ) ;
71- if ( contentBuilder . Length > 0 )
72- assistantMessage . Content . Add ( ChatMessageContentPart . CreateTextPart ( contentBuilder . ToString ( ) ) ) ;
73- messages . Add ( assistantMessage ) ;
74-
75- foreach ( var call in calls )
76- {
77- var result = await ChatTools . Process ( call , onUpdate ) ;
78- messages . Add ( result ) ;
79- }
80-
81- inProgress = true ;
82- break ;
67+ var result = await ChatTools . Process ( call , onUpdate ) ;
68+ messages . Add ( result ) ;
8369 }
84- case ChatFinishReason . ContentFilter :
85- throw new Exception ( "Ommitted content due to a content filter flag" ) ;
86- default :
87- break ;
88- }
8970
71+ inProgress = true ;
72+ break ;
73+ }
74+ case ChatFinishReason . ContentFilter :
75+ throw new Exception ( "Ommitted content due to a content filter flag" ) ;
76+ default :
77+ break ;
9078 }
9179
9280 if ( ! inProgress )
0 commit comments