Skip to content

Commit

Permalink
Merge pull request #554 from Lezune/users/Lezune/Foundations-FineTune…
Browse files Browse the repository at this point in the history
…s-Update

CODE RUB: Foundations FineTunes Exceptions Update v2.10.1
  • Loading branch information
glhays authored Jun 12, 2024
2 parents 7c6c02a + b8354bd commit 6910519
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ private async Task ShouldThrowValidationExceptionOnSubmitIfFineTuneIsNullAsync()
FineTune nullFineTune = null;

var nullFineTuneException =
new NullFineTuneException();
new NullFineTuneException(
message: "Fine tune is null.");

var expectedFineTuneValidationException =
new FineTuneValidationException(
Expand Down Expand Up @@ -60,7 +61,7 @@ private async Task ShouldThrowValidationExceptionOnSubmitIfFineTuneRequestIsNull
fineTune.Request = nullFineTuneRequest;

var invalidFineTuneException =
new InvalidFineTuneException();
createInvalidFineTuneException();

invalidFineTuneException.AddData(
key: nameof(FineTune.Request),
Expand Down Expand Up @@ -104,7 +105,8 @@ private async Task ShouldThrowValidationExceptionOnSubmitIfFineTuneRequestIsInva
var invalidFineTune = new FineTune();
invalidFineTune.Request = new FineTuneRequest();
invalidFineTune.Request.FileId = invalidText;
var invalidFineTuneException = new InvalidFineTuneException();
var invalidFineTuneException =
createInvalidFineTuneException();

invalidFineTuneException.AddData(
key: nameof(FineTuneRequest.FileId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Standard.AI.OpenAI.Brokers.OpenAIs;
using Standard.AI.OpenAI.Models.Services.Foundations.ExternalFineTunes;
using Standard.AI.OpenAI.Models.Services.Foundations.FineTunes;
using Standard.AI.OpenAI.Models.Services.Foundations.FineTunes.Exceptions;
using Standard.AI.OpenAI.Services.Foundations.FineTunes;
using Tynamix.ObjectFiller;
using Xunit;
Expand Down Expand Up @@ -186,5 +187,11 @@ private static Filler<FineTune> CreateRandomFineTuneFiller()

return filler;
}

private InvalidFineTuneException createInvalidFineTuneException()
{
return new InvalidFineTuneException(
message: "Fine tune is invalid.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.FineTunes.Exceptions
{
public class ExcessiveCallFineTuneException : Xeption
{
public ExcessiveCallFineTuneException(Exception innerException)
: base(
message: "Excessive call error occurred, limit your calls.",
innerException: innerException)
{ }

public ExcessiveCallFineTuneException(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.FineTunes.Exceptions
{
public class FailedFineTuneServiceException : Xeption
{
public FailedFineTuneServiceException(Exception innerException)
: base(
message: "Failed fine tune error occurred, contact support.",
innerException: innerException)
{ }

public FailedFineTuneServiceException(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.FineTunes.Exceptions
{
public class FailedServerFineTuneException : Xeption
{
public FailedServerFineTuneException(Exception innerException)
: base(
message: "Failed fine tune server error occurred, contact support.",
innerException: innerException)
{ }

public FailedServerFineTuneException(string message, Exception innerException)
: base(message: 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.FineTunes.Exceptions
{
public class FineTuneDependencyException : Xeption
{
public FineTuneDependencyException(Xeption innerException)
: base(
message: "Fine tune dependency error ocurred, contact support.",
innerException: innerException)
{ }

public FineTuneDependencyException(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.FineTunes.Exceptions
{
public class FineTuneDependencyValidationException : Xeption
{
public FineTuneDependencyValidationException(Xeption innerException)
: base(
message: "Fine tune dependency validation error occurred, fix errors and try again",
innerException: innerException)
{ }

public FineTuneDependencyValidationException(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.FineTunes.Exceptions
{
public class FineTuneServiceException : Xeption
{
public FineTuneServiceException(Xeption innerException)
: base(
message: "Fine tune error ocurred, contact support.",
innerException: innerException)
{ }

public FineTuneServiceException(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.FineTunes.Exceptions
{
public class FineTuneValidationException : Xeption
{
public FineTuneValidationException(Xeption innerException)
: base(
message: "Fine tune validation error occurred, fix errors and try again.",
innerException: innerException)
{ }

public FineTuneValidationException(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.FineTunes.Exceptions
{
public class InvalidFineTuneConfigurationException : Xeption
{
public InvalidFineTuneConfigurationException(Exception innerException)
: base(
message: "Invalid fine tune configuration error ocurred, contact support.",
innerException: innerException)
{ }

public InvalidFineTuneConfigurationException(string message, Exception innerException)
: base(message, innerException)
{ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.FineTunes.Exceptions
{
public class InvalidFineTuneException : Xeption
{
public InvalidFineTuneException()
: base(message: "Fine tune is invalid.")
{ }

public InvalidFineTuneException(Exception innerException)
: base(
message: "Fine tune is invalid.",
innerException: innerException)
public InvalidFineTuneException(string message)
: base(message)
{ }

public InvalidFineTuneException(string message, Exception 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.FineTunes.Exceptions
{
public class NullFineTuneException : Xeption
{
public NullFineTuneException()
: base(
message: "Fine tune is null.")
public NullFineTuneException(string message)
: base(message)
{ }

public NullFineTuneException(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.FineTunes.Exceptions
{
public class UnauthorizedFineTuneException : Xeption
{
public UnauthorizedFineTuneException(Exception innerException)
: base(
message: "Unauthorized fine tune request, fix errors and try again.",
innerException: innerException)
{ }

public UnauthorizedFineTuneException(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.FineTunes;
using Standard.AI.OpenAI.Models.Services.Foundations.FineTunes.Exceptions;
using Xeptions;

namespace Standard.AI.OpenAI.Services.Foundations.FineTunes
{
Expand All @@ -22,64 +23,113 @@ private static async ValueTask<FineTune> TryCatch(ReturningFineTuneFunction retu
}
catch (NullFineTuneException nullFineTuneException)
{
throw new FineTuneValidationException(nullFineTuneException);
throw CreateFineTuneValidationException(
nullFineTuneException);
}
catch (InvalidFineTuneException invalidFineTuneException)
{
throw new FineTuneValidationException(invalidFineTuneException);
throw CreateFineTuneValidationException(
invalidFineTuneException);
}
catch (HttpResponseUrlNotFoundException httpResponseUrlNotFoundException)
{
var invalidFineTuneConfigurationException =
new InvalidFineTuneConfigurationException(httpResponseUrlNotFoundException);
new InvalidFineTuneConfigurationException(
message: "Invalid fine tune configuration error ocurred, contact support.",
httpResponseUrlNotFoundException);

throw new FineTuneDependencyException(invalidFineTuneConfigurationException);
throw CreateFineTuneDependencyException(
invalidFineTuneConfigurationException);
}
catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException)
{
var unauthorizedFineTuneException =
new UnauthorizedFineTuneException(
message: "Unauthorized fine tune request, fix errors and try again.",
httpResponseUnauthorizedException);

throw new FineTuneDependencyException(unauthorizedFineTuneException);
throw CreateFineTuneDependencyException(
unauthorizedFineTuneException);
}
catch (HttpResponseForbiddenException httpResponseForbiddenException)
{
var unauthorizedFineTuneException =
new UnauthorizedFineTuneException(
message: "Unauthorized fine tune request, fix errors and try again.",
httpResponseForbiddenException);

throw new FineTuneDependencyException(unauthorizedFineTuneException);
throw CreateFineTuneDependencyException(
unauthorizedFineTuneException);
}
catch (HttpResponseBadRequestException httpResponseBadRequestException)
{
var invalidFineTuneException =
new InvalidFineTuneException(
message: "Fine tune is invalid.",
httpResponseBadRequestException);

throw new FineTuneDependencyValidationException(invalidFineTuneException);
throw CreateFineTuneDependencyValidationException(
invalidFineTuneException);
}
catch (HttpResponseTooManyRequestsException httpResponseTooManyRequestsException)
{
var excessiveCallFineTuneException =
new ExcessiveCallFineTuneException(httpResponseTooManyRequestsException);
new ExcessiveCallFineTuneException(
message: "Excessive call error occurred, limit your calls.",
httpResponseTooManyRequestsException);

throw new FineTuneDependencyValidationException(excessiveCallFineTuneException);
throw CreateFineTuneDependencyValidationException(
excessiveCallFineTuneException);
}
catch (HttpResponseException httpResponseException)
{
var failedServerFineTuneException =
new FailedServerFineTuneException(httpResponseException);
new FailedServerFineTuneException(
message: "Failed fine tune server error occurred, contact support.",
httpResponseException);

throw new FineTuneDependencyException(failedServerFineTuneException);
throw CreateFineTuneDependencyException(
failedServerFineTuneException);
}
catch (Exception exception)
{
var failedFineTuneServiceException =
new FailedFineTuneServiceException(exception);
new FailedFineTuneServiceException(
message: "Failed fine tune error occurred, contact support.",
exception);

throw new FineTuneServiceException(failedFineTuneServiceException);
throw CreateFineTuneServiceException(
failedFineTuneServiceException);
}
}

private static FineTuneValidationException CreateFineTuneValidationException(Xeption innerException)
{
return new FineTuneValidationException(
message: "Fine tune validation error occurred, fix errors and try again.",
innerException);
}

private static FineTuneDependencyException CreateFineTuneDependencyException(Xeption innerException)
{
return new FineTuneDependencyException(
message: "Fine tune dependency error ocurred, contact support.",
innerException);
}

private static FineTuneDependencyValidationException CreateFineTuneDependencyValidationException(
Xeption innerException)
{
return new FineTuneDependencyValidationException(
message: "Fine tune dependency validation error occurred, fix errors and try again",
innerException);
}

private static FineTuneServiceException CreateFineTuneServiceException(Xeption innerException)
{
return new FineTuneServiceException(
message: "Fine tune error ocurred, contact support.",
innerException);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ private static void ValidateFineTuneNotNull(FineTune fineTune)
{
if (fineTune is null)
{
throw new NullFineTuneException();
throw new NullFineTuneException(
message: "Fine tune is null.");
}
}

private static void Validate(params (dynamic Rule, string Parameter)[] validations)
{
var invalidFineTuneException = new InvalidFineTuneException();
var invalidFineTuneException =
new InvalidFineTuneException(
message: "Fine tune is invalid.");

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

0 comments on commit 6910519

Please sign in to comment.