Skip to content

Commit

Permalink
CopilotChat: Make Azure Speech optional on the backend and don't show…
Browse files Browse the repository at this point in the history
… errors when not configured on the frontend (#652)

### Motivation and Context
Fix for failures when AzureSpeech is not configured.

### Description
Made AzureSpeech options optional and return OK with a token response
that is marked as not successful.
  • Loading branch information
adrianwyatt authored and dluc committed Apr 29, 2023
1 parent 6c2b1c6 commit d78e397
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ public sealed class AzureSpeechOptions
/// <summary>
/// Location of the Azure speech service to use (e.g. "South Central US")
/// </summary>
[Required, NotEmptyOrWhitespace]
public string? Region { get; set; } = string.Empty;

/// <summary>
/// Key to access the Azure speech service.
/// </summary>
[Required, NotEmptyOrWhitespace]
public string Key { get; set; } = string.Empty;
public string? Key { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public SpeechTokenController(IOptions<AzureSpeechOptions> options, ILogger<Speec
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<SpeechTokenResponse>> GetAsync()
{
if (string.IsNullOrWhiteSpace(this._options.Region))
// Azure Speech token support is optional. If the configuration is missing or incomplete, return an unsuccessful token response.
if (string.IsNullOrWhiteSpace(this._options.Region) ||
string.IsNullOrWhiteSpace(this._options.Key))
{
throw new InvalidOperationException($"Missing value for {AzureSpeechOptions.PropertyName}:{nameof(this._options.Region)}");
return new SpeechTokenResponse { IsSuccess = false };
}

string fetchTokenUri = "https://" + this._options.Region + ".api.cognitive.microsoft.com/sts/v1.0/issueToken";
Expand Down

0 comments on commit d78e397

Please sign in to comment.