Skip to content

Commit

Permalink
OpenAIInvalidResponseException is replaced by SKException
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMenshykh committed Jul 19, 2023
1 parent f51df1c commit 3d6cb2b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public abstract class ClientBase

if (response == null)
{
throw new OpenAIInvalidResponseException<Completions>(null, "Text completions null response");
throw new AIException(AIException.ErrorCodes.InvalidResponseContent, "Text completions null response");
}

var responseData = response.Value;

if (responseData.Choices.Count == 0)
{
throw new OpenAIInvalidResponseException<Completions>(responseData, "Text completions not found");
throw new AIException(AIException.ErrorCodes.InvalidResponseContent, "Text completions not found");
}

return responseData.Choices.Select(choice => new TextResult(responseData, choice)).ToList();
Expand Down Expand Up @@ -119,12 +119,12 @@ await foreach (StreamingChoice choice in streamingChatCompletions.GetChoicesStre

if (response == null)
{
throw new OpenAIInvalidResponseException<Embeddings>(null, "Text embedding null response");
throw new AIException(AIException.ErrorCodes.InvalidResponseContent, "Text embedding null response");
}

if (response.Value.Data.Count == 0)
{
throw new OpenAIInvalidResponseException<Embeddings>(response.Value, "Text embedding not found");
throw new AIException(AIException.ErrorCodes.InvalidResponseContent, "Text embedding not found");
}

EmbeddingItem x = response.Value.Data[0];
Expand Down Expand Up @@ -158,12 +158,12 @@ await foreach (StreamingChoice choice in streamingChatCompletions.GetChoicesStre

if (response == null)
{
throw new OpenAIInvalidResponseException<ChatCompletions>(null, "Chat completions null response");
throw new AIException(AIException.ErrorCodes.InvalidResponseContent, "Chat completions null response");
}

if (response.Value.Choices.Count == 0)
{
throw new OpenAIInvalidResponseException<ChatCompletions>(response.Value, "Chat completions not found");
throw new AIException(AIException.ErrorCodes.InvalidResponseContent, "Chat completions not found");
}

return response.Value.Choices.Select(chatChoice => new ChatResult(response.Value, chatChoice)).ToList();
Expand Down Expand Up @@ -193,7 +193,7 @@ await foreach (StreamingChoice choice in streamingChatCompletions.GetChoicesStre

if (response is null)
{
throw new OpenAIInvalidResponseException<StreamingChatCompletions>(null, "Chat completions null response");
throw new AIException(AIException.ErrorCodes.InvalidResponseContent, "Chat completions null response");
}

using StreamingChatCompletions streamingChatCompletions = response.Value;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ public async Task<string> GenerateImageAsync(string description, int width, int

if (result.Result == null)
{
throw new AzureSdk.OpenAIInvalidResponseException<AzureImageGenerationResponse>(null, "Azure Image Generation null response");
throw new AIException(AIException.ErrorCodes.InvalidResponseContent, "Azure Image Generation null response");
}

if (result.Result.Images.Count == 0)
{
throw new AzureSdk.OpenAIInvalidResponseException<AzureImageGenerationResponse>(result, "Azure Image Generation result not found");
throw new AIException(AIException.ErrorCodes.InvalidResponseContent, "Azure Image Generation result not found");
}

return result.Result.Images.First().Url;
Expand Down Expand Up @@ -184,7 +184,7 @@ private async Task<AzureImageGenerationResponse> GetImageGenerationResultAsync(s
}
else if (this.IsFailedOrCancelled(result.Status))
{
throw new AzureSdk.OpenAIInvalidResponseException<AzureImageGenerationResponse>(result, $"Azure OpenAI image generation {result.Status}");
throw new AIException(AIException.ErrorCodes.InvalidResponseContent, $"Azure OpenAI image generation {result.Status}");
}

if (response.Headers.TryGetValues("retry-after", out var afterValues) && long.TryParse(afterValues.FirstOrDefault(), out var after))
Expand Down

0 comments on commit 3d6cb2b

Please sign in to comment.