Skip to content

Commit

Permalink
Merge pull request #557 from Lezune/users/Lezune/Foundations-Completi…
Browse files Browse the repository at this point in the history
…ons-Update

CODE RUB: Models/Services/Foundations/Completions/Exceptions Update v2.10.1
  • Loading branch information
hassanhabib authored Jun 10, 2024
2 parents 5507463 + 4c47b82 commit ae1a463
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ private async Task ShouldThrowValidationExceptionOnPromptIfCompletionIsNullAsync
{
// given
Completion nullCompletion = null;
var nullCompletionException = new NullCompletionException();
var nullCompletionException =
new NullCompletionException(
message: "Completion is null.");

var exceptedCompletionValidationException =
new CompletionValidationException(
Expand Down Expand Up @@ -56,7 +58,7 @@ private async Task ShouldThrowValidationExceptionOnPromptIfRequestIsNullAsync()
invalidCompletion.Request = null;

var invalidCompletionException =
new InvalidCompletionException();
CreateInvalidCompletionException();

invalidCompletionException.AddData(
key: nameof(Completion.Request),
Expand Down Expand Up @@ -103,7 +105,8 @@ private async Task ShouldThrowValidationExceptionOnPromptIfCompletionIsInvalidAs
}
};

var invalidCompletionException = new InvalidCompletionException();
var invalidCompletionException =
CreateInvalidCompletionException();

invalidCompletionException.AddData(
key: nameof(CompletionRequest.Model),
Expand Down Expand Up @@ -146,7 +149,8 @@ private async Task ShouldThrowValidationExceptionOnPromptIfPromptIsEmptyAsync()
}
};

var invalidCompletionException = new InvalidCompletionException();
var invalidCompletionException =
CreateInvalidCompletionException();

invalidCompletionException.AddData(
key: nameof(CompletionRequest.Prompts),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Standard.AI.OpenAI.Brokers.DateTimes;
using Standard.AI.OpenAI.Brokers.OpenAIs;
using Standard.AI.OpenAI.Models.Services.Foundations.Completions;
using Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions;
using Standard.AI.OpenAI.Models.Services.Foundations.ExternalCompletions;
using Standard.AI.OpenAI.Services.Foundations.Completions;
using Tynamix.ObjectFiller;
Expand Down Expand Up @@ -141,5 +142,11 @@ private static Filler<Completion> CreateCompletionFiller()

return filler;
}

private static InvalidCompletionException CreateInvalidCompletionException()
{
return new InvalidCompletionException(
message: "Invalid completion error occurred, fix errors and try again.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class CompletionDependencyException : Xeption
{
public CompletionDependencyException(Xeption innerException)
: base(
message: "Completion dependency error occurred, contact support.",
innerException: innerException)
{ }

public CompletionDependencyException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class CompletionDependencyValidationException : Xeption
{
public CompletionDependencyValidationException(Xeption innerException)
: base(
message: "Completion dependency validation error occurred, fix errors and try again.",
innerException: innerException)
{ }

public CompletionDependencyValidationException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class CompletionServiceException : Xeption
{
public CompletionServiceException(Xeption innerException)
: base(
message: "Completion service error occurred, contact support.",
innerException: innerException)
{ }

public CompletionServiceException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class CompletionValidationException : Xeption
{
public CompletionValidationException(Xeption innerException)
: base(
message: "Completion validation error occurred, fix errors and try again.",
innerException: innerException)
{ }

public CompletionValidationException(string message, Xeption innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class ExcessiveCallCompletionException : Xeption
{
public ExcessiveCallCompletionException(Exception innerException)
: base(
message: "Excessive call error occurred, limit your calls.",
innerException: innerException)
{ }

public ExcessiveCallCompletionException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class FailedCompletionServiceException : Xeption
{
public FailedCompletionServiceException(Exception innerException)
: base(
message: "Failed completion error occurred, contact support.",
innerException: innerException)
{ }

public FailedCompletionServiceException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class FailedServerCompletionException : Xeption
{
public FailedServerCompletionException(Exception innerException)
: base(
message: "Failed server completion error occurred, contact support.",
innerException: innerException)
{ }

public FailedServerCompletionException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class InvalidCompletionException : Xeption
{
public InvalidCompletionException()
: base(
message: "Invalid completion error occurred, fix errors and try again.")
public InvalidCompletionException(string message)
: base(message)
{ }

public InvalidCompletionException(Exception innerException)
: base(
message: "Invalid completion error occurred, fix errors and try again.",
innerException: innerException)
{ }

public InvalidCompletionException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class InvalidConfigurationCompletionException : Xeption
{
public InvalidConfigurationCompletionException(Exception innerException)
: base(
message: "Invalid configuration error occurred, fix errors and try again.",
innerException: innerException)
{ }

public InvalidConfigurationCompletionException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class NotFoundCompletionException : Xeption
{
public NotFoundCompletionException(Exception innerException)
: base(
message: "Not found completion error occurred, fix errors and try again.",
innerException: innerException)
{ }

public NotFoundCompletionException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class NullCompletionException : Xeption
{
public NullCompletionException()
: base(
message: "Completion is null.")
public NullCompletionException(string message)
: base(message)
{ }

public NullCompletionException(string message, Xeption innerException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions
{
public class UnauthorizedCompletionException : Xeption
{
public UnauthorizedCompletionException(Exception innerException)
: base(
message: "Unauthorized completion request, fix errors and try again.",
innerException: innerException)
{ }

public UnauthorizedCompletionException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using RESTFulSense.Exceptions;
using Standard.AI.OpenAI.Models.Services.Foundations.Completions;
using Standard.AI.OpenAI.Models.Services.Foundations.Completions.Exceptions;
using Xeptions;

namespace Standard.AI.OpenAI.Services.Foundations.Completions
{
Expand All @@ -22,70 +23,123 @@ private static async ValueTask<Completion> TryCatch(ReturningCompletionFunction
}
catch (NullCompletionException nullCompletionException)
{
throw new CompletionValidationException(nullCompletionException);
throw CreateCompletionValidationException(
nullCompletionException);
}
catch (InvalidCompletionException invalidCompletionException)
{
throw new CompletionValidationException(
throw CreateCompletionValidationException(
invalidCompletionException);
}
catch (HttpResponseUrlNotFoundException httpResponseUrlNotFoundException)
{
var invalidConfigurationCompletionException =
new InvalidConfigurationCompletionException(httpResponseUrlNotFoundException);
new InvalidConfigurationCompletionException(
message: "Invalid configuration error occurred, fix errors and try again.",
httpResponseUrlNotFoundException);

throw new CompletionDependencyException(invalidConfigurationCompletionException);
throw CreateCompletionDependencyException(
invalidConfigurationCompletionException);
}
catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException)
{
var unauthorizedCompletionException =
new UnauthorizedCompletionException(httpResponseUnauthorizedException);
new UnauthorizedCompletionException(
message: "Unauthorized completion request, fix errors and try again.",
httpResponseUnauthorizedException);

throw new CompletionDependencyException(unauthorizedCompletionException);
throw CreateCompletionDependencyException(
unauthorizedCompletionException);
}
catch (HttpResponseForbiddenException httpResponseForbiddenException)
{
var unauthorizedCompletionException =
new UnauthorizedCompletionException(httpResponseForbiddenException);
new UnauthorizedCompletionException(
message: "Unauthorized completion request, fix errors and try again.",
httpResponseForbiddenException);

throw new CompletionDependencyException(unauthorizedCompletionException);
throw CreateCompletionDependencyException(
unauthorizedCompletionException);
}
catch (HttpResponseNotFoundException httpResponseNotFoundException)
{
var notFoundCompletionException =
new NotFoundCompletionException(httpResponseNotFoundException);
new NotFoundCompletionException(
message: "Not found completion error occurred, fix errors and try again.",
httpResponseNotFoundException);

throw new CompletionDependencyValidationException(notFoundCompletionException);
throw CreateCompletionDependencyValidationException(
notFoundCompletionException);
}
catch (HttpResponseBadRequestException httpResponseBadRequestException)
{
var invalidCompletionException =
new InvalidCompletionException(httpResponseBadRequestException);
new InvalidCompletionException(
message: "Invalid completion error occurred, fix errors and try again.",
httpResponseBadRequestException);

throw new CompletionDependencyValidationException(invalidCompletionException);
throw CreateCompletionDependencyValidationException(
invalidCompletionException);
}

catch (HttpResponseTooManyRequestsException httpResponseTooManyRequestsException)
{
var excessiveCallCompletionException =
new ExcessiveCallCompletionException(httpResponseTooManyRequestsException);
new ExcessiveCallCompletionException(
message: "Excessive call error occurred, limit your calls.",
httpResponseTooManyRequestsException);

throw new CompletionDependencyValidationException(excessiveCallCompletionException);
throw CreateCompletionDependencyValidationException(
excessiveCallCompletionException);
}
catch (HttpResponseException httpResponseException)
{
var failedServerCompletionException =
new FailedServerCompletionException(httpResponseException);
new FailedServerCompletionException(
message: "Failed server completion error occurred, contact support.",
httpResponseException);

throw new CompletionDependencyException(failedServerCompletionException);
throw CreateCompletionDependencyException(
failedServerCompletionException);
}
catch (Exception exception)
{
var failedCompletionServiceException =
new FailedCompletionServiceException(exception);
new FailedCompletionServiceException(
message: "Failed completion error occurred, contact support.",
exception);

throw new CompletionServiceException(failedCompletionServiceException);
throw CreateCompletionServiceException(
failedCompletionServiceException);
}
}

private static CompletionValidationException CreateCompletionValidationException(Xeption innerException)
{
return new CompletionValidationException(
message: "Completion validation error occurred, fix errors and try again.",
innerException);
}

private static CompletionDependencyException CreateCompletionDependencyException(Xeption innerException)
{
return new CompletionDependencyException(
message: "Completion dependency error occurred, contact support.",
innerException);
}

private static CompletionDependencyValidationException CreateCompletionDependencyValidationException(Xeption innerException)
{
return new CompletionDependencyValidationException(
message: "Completion dependency validation error occurred, fix errors and try again.",
innerException);
}

private static CompletionServiceException CreateCompletionServiceException(Xeption innerException)
{
return new CompletionServiceException(
message: "Completion service error occurred, contact support.",
innerException);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ private static void ValidateCompletionNotNull(Completion completion)
{
if (completion is null)
{
throw new NullCompletionException();
throw new NullCompletionException(
message: "Completion is null.");
}
}

Expand Down Expand Up @@ -55,7 +56,9 @@ private static void ValidateCompletionRequestNotNull(CompletionRequest request)

private static void Validate(params (dynamic Rule, string Parameter)[] validations)
{
var invalidCompletionException = new InvalidCompletionException();
var invalidCompletionException =
new InvalidCompletionException(
message: "Invalid completion error occurred, fix errors and try again.");

foreach ((dynamic rule, string parameter) in validations)
{
Expand Down
Loading

0 comments on commit ae1a463

Please sign in to comment.