Skip to content

Commit e4d1651

Browse files
committed
code_style: check null once time
Signed-off-by: leo <longshuang@msn.cn>
1 parent 838c5d1 commit e4d1651

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/AI/Agent.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,19 @@ public async Task GenerateCommitMessageAsync(string repo, string changeList, Act
4141
switch (completion.FinishReason)
4242
{
4343
case ChatFinishReason.Stop:
44-
onUpdate?.Invoke(string.Empty);
45-
onUpdate?.Invoke("# Assistant");
46-
if (completion.Content.Count > 0)
47-
onUpdate?.Invoke(completion.Content[0].Text);
48-
else
49-
onUpdate?.Invoke("[No content was generated.]");
44+
if (onUpdate != null)
45+
{
46+
onUpdate.Invoke(string.Empty);
47+
onUpdate.Invoke("# Assistant");
48+
if (completion.Content.Count > 0)
49+
onUpdate.Invoke(completion.Content[0].Text);
50+
else
51+
onUpdate.Invoke("[No content was generated.]");
5052

51-
onUpdate?.Invoke(string.Empty);
52-
onUpdate?.Invoke("# Token Usage");
53-
onUpdate?.Invoke($"Total: {completion.Usage.TotalTokenCount}. Input: {completion.Usage.InputTokenCount}. Output: {completion.Usage.OutputTokenCount}");
53+
onUpdate.Invoke(string.Empty);
54+
onUpdate.Invoke("# Token Usage");
55+
onUpdate.Invoke($"Total: {completion.Usage.TotalTokenCount}. Input: {completion.Usage.InputTokenCount}. Output: {completion.Usage.OutputTokenCount}");
56+
}
5457
break;
5558
case ChatFinishReason.Length:
5659
throw new Exception("The response was cut off because it reached the maximum length. Consider increasing the max tokens limit.");

0 commit comments

Comments
 (0)