Skip to content

Fix a null-ref exception and add telemetry for error response from Az Copilot #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions shell/agents/Microsoft.Azure.Agent/AzureAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ public async Task<bool> ChatAsync(string input, IShell shell)

if (_copilotResponse.IsError)
{
string errorMessage = _copilotResponse.Text;
Telemetry.Trace(AzTrace.Exception(errorMessage));
host.WriteErrorLine()
.WriteErrorLine(_copilotResponse.Text)
.WriteErrorLine(errorMessage)
.WriteErrorLine();
}
else
Expand Down Expand Up @@ -300,21 +302,25 @@ public async Task<bool> ChatAsync(string input, IShell shell)
}
}

// The 'ConversationState' could be null when Azure Copilot returns an error response.
var conversationState = _copilotResponse.ConversationState;
_turnsLeft = conversationState.TurnLimit - conversationState.TurnNumber;
if (_turnsLeft <= 5)
if (conversationState is not null)
{
string message = _turnsLeft switch
_turnsLeft = conversationState.TurnLimit - conversationState.TurnNumber;
if (_turnsLeft <= 5)
{
1 => $"[yellow]{_turnsLeft} request left[/]",
0 => $"[red]{_turnsLeft} request left[/]",
_ => $"[yellow]{_turnsLeft} requests left[/]",
};
string message = _turnsLeft switch
{
1 => $"[yellow]{_turnsLeft} request left[/]",
0 => $"[red]{_turnsLeft} request left[/]",
_ => $"[yellow]{_turnsLeft} requests left[/]",
};

host.RenderDivider(message, DividerAlignment.Right);
if (_turnsLeft is 0)
{
host.WriteLine("\nYou've reached the maximum length of a conversation. To continue, please run '/refresh' to start a new conversation.\n");
host.RenderDivider(message, DividerAlignment.Right);
if (_turnsLeft is 0)
{
host.WriteLine("\nYou've reached the maximum length of a conversation. To continue, please run '/refresh' to start a new conversation.\n");
}
}
}

Expand Down