diff --git a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIModels/AIModelServiceTests.Validations.RetrieveByName.cs b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIModels/AIModelServiceTests.Validations.RetrieveByName.cs index 2232ec3e..eee8bb76 100644 --- a/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIModels/AIModelServiceTests.Validations.RetrieveByName.cs +++ b/Standard.AI.OpenAI.Tests.Unit/Services/Foundations/AIModels/AIModelServiceTests.Validations.RetrieveByName.cs @@ -22,7 +22,8 @@ private async Task ShouldThrowValidationExceptionOnRetrieveModelByNameIfModelNam { // given var invalidAIModelException = - new InvalidAIModelException(); + new InvalidAIModelException( + message: "AI Model is invalid."); invalidAIModelException.AddData( key: nameof(AIModel.Name), diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelDependencyException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelDependencyException.cs index d46f6ca2..91e66083 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelDependencyException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelDependencyException.cs @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { internal class AIModelDependencyException : Xeption { - public AIModelDependencyException(Xeption innerException) - : base( - message: "AI Model dependency error occurred, contact support.", - innerException: innerException) - { } - public AIModelDependencyException(string message, Xeption innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelDependencyValidationException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelDependencyValidationException.cs index c1c9e541..fc8e31bf 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelDependencyValidationException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelDependencyValidationException.cs @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { internal class AIModelDependencyValidationException : Xeption { - public AIModelDependencyValidationException(Xeption innerException) - : base( - message: "AI Model dependency validation error occurred, fix errors and try again.", - innerException: innerException) - { } - public AIModelDependencyValidationException(string message, Xeption innerException) : base(message: message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelServiceException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelServiceException.cs index 26e26273..d9e22db0 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelServiceException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelServiceException.cs @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { public class AIModelServiceException : Xeption { - public AIModelServiceException(Xeption innerException) - : base( - message: "AI Model service error occurred, contact support.", - innerException: innerException) - { } - public AIModelServiceException(string message, Xeption innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelValidationException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelValidationException.cs index a2eba438..6a25bd4b 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelValidationException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/AIModelValidationException.cs @@ -8,12 +8,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { public class AIModelValidationException : Xeption { - public AIModelValidationException(Xeption innerException) - : base( - message: "AI Model validation error occurred, fix errors and try again.", - innerException: innerException) - { } - public AIModelValidationException(string message, Xeption innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/ExcessiveCallAIModelException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/ExcessiveCallAIModelException.cs index ab551e35..ddc0f967 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/ExcessiveCallAIModelException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/ExcessiveCallAIModelException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { internal class ExcessiveCallAIModelException : Xeption { - public ExcessiveCallAIModelException(Exception innerException) - : base( - message: "Excessive call error occurred, limit your calls.", - innerException: innerException) - { } - public ExcessiveCallAIModelException(string message, Exception innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/FailedAIModelServiceException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/FailedAIModelServiceException.cs index 28f50dd1..37bcca2f 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/FailedAIModelServiceException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/FailedAIModelServiceException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { public class FailedAIModelServiceException : Xeption { - public FailedAIModelServiceException(Exception innerException) - : base( - message: "Failed AI Model Service Exception occurred, please contact support for assistance.", - innerException: innerException) - { } - public FailedAIModelServiceException(string message, Exception innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/FailedServerAIModelException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/FailedServerAIModelException.cs index d0056af7..03dc7abc 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/FailedServerAIModelException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/FailedServerAIModelException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { public class FailedServerAIModelException : Xeption { - public FailedServerAIModelException(Exception innerException) - : base( - message: "Failed AI Model server error occurred, contact support", - innerException: innerException) - { } - public FailedServerAIModelException(string message, Exception innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/InvalidAIModelException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/InvalidAIModelException.cs index 25eafc57..f7d09fc0 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/InvalidAIModelException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/InvalidAIModelException.cs @@ -9,15 +9,8 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { public class InvalidAIModelException : Xeption { - public InvalidAIModelException() - : base( - message: "AI Model is invalid.") - { } - - public InvalidAIModelException(Exception innerException) - : base( - message: "AI Model is invalid.", - innerException: innerException) + public InvalidAIModelException(string message) + : base(message) { } public InvalidAIModelException(string message, Exception innerException) diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/InvalidConfigurationAIModelException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/InvalidConfigurationAIModelException.cs index d0b86c1d..45fc3985 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/InvalidConfigurationAIModelException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/InvalidConfigurationAIModelException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { public class InvalidConfigurationAIModelException : Xeption { - public InvalidConfigurationAIModelException(Exception innerException) - : base( - message: "Invalid AI Model configuration error occurred, contact support.", - innerException: innerException) - { } - public InvalidConfigurationAIModelException(string message, Exception innerException) : base(message, innerException) { } } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/NotFoundAIModelException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/NotFoundAIModelException.cs index e60b4fbd..1ee98e83 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/NotFoundAIModelException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/NotFoundAIModelException.cs @@ -9,12 +9,6 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { public class NotFoundAIModelException : Xeption { - public NotFoundAIModelException(Exception innerException) - : base( - message: "AI Model not found.", - innerException: innerException) - { } - public NotFoundAIModelException(string message, Exception innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/UnauthorizedAIModelException.cs b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/UnauthorizedAIModelException.cs index 7547e067..5dbed051 100644 --- a/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/UnauthorizedAIModelException.cs +++ b/Standard.AI.OpenAI/Models/Services/Foundations/AIModels/Exceptions/UnauthorizedAIModelException.cs @@ -8,13 +8,7 @@ namespace Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions { public class UnauthorizedAIModelException : Xeption - { - public UnauthorizedAIModelException(Exception innerException) - : base( - message: "Unauthorized AI Model error occurred, fix errors and try again.", - innerException: innerException) - { } - + { public UnauthorizedAIModelException(string message, Exception innerException) : base(message, innerException) { } diff --git a/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.Exceptions.cs b/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.Exceptions.cs index f16afaf0..611bba68 100644 --- a/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.Exceptions.cs +++ b/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.Exceptions.cs @@ -8,6 +8,7 @@ using RESTFulSense.Exceptions; using Standard.AI.OpenAI.Models.Services.Foundations.AIModels; using Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions; +using Xeptions; namespace Standard.AI.OpenAI.Services.Foundations.AIModels { @@ -24,63 +25,87 @@ private async ValueTask TryCatch(ReturningAIModelFunction returningAIMo } catch (InvalidAIModelException invalidAIModelException) { - throw new AIModelValidationException(invalidAIModelException); + throw CreateAIModelValidationException( + invalidAIModelException); } catch (HttpResponseUrlNotFoundException httpResponseUrlNotFoundException) { var invalidConfigurationAIModelException = - new InvalidConfigurationAIModelException(httpResponseUrlNotFoundException); + new InvalidConfigurationAIModelException( + message: "Invalid AI Model configuration error occurred, contact support.", + httpResponseUrlNotFoundException); - throw new AIModelDependencyException(invalidConfigurationAIModelException); + throw CreateAIModelDependencyException( + invalidConfigurationAIModelException); } catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException) { var unauthorizedAIModelException = - new UnauthorizedAIModelException(httpResponseUnauthorizedException); + new UnauthorizedAIModelException( + message: "Unauthorized AI Model error occurred, fix errors and try again.", + httpResponseUnauthorizedException); - throw new AIModelDependencyException(unauthorizedAIModelException); + throw CreateAIModelDependencyException( + unauthorizedAIModelException); } catch (HttpResponseForbiddenException httpResponseForbiddenException) { var unauthorizedAIModelException = - new UnauthorizedAIModelException(httpResponseForbiddenException); + new UnauthorizedAIModelException( + message: "Unauthorized AI Model error occurred, fix errors and try again.", + httpResponseForbiddenException); - throw new AIModelDependencyException(unauthorizedAIModelException); + throw CreateAIModelDependencyException( + unauthorizedAIModelException); } catch (HttpResponseNotFoundException httpResponseNotFoundException) { var notFoundAIModelException = - new NotFoundAIModelException(httpResponseNotFoundException); + new NotFoundAIModelException( + message: "AI Model not found.", + httpResponseNotFoundException); - throw new AIModelDependencyValidationException(notFoundAIModelException); + throw CreateAIModelDependencyValidationException( + notFoundAIModelException); } catch (HttpResponseBadRequestException httpResponseBadRequestException) { var invalidAIModelException = - new InvalidAIModelException(httpResponseBadRequestException); + new InvalidAIModelException( + message: "AI Model is invalid.", + httpResponseBadRequestException); - throw new AIModelDependencyValidationException(invalidAIModelException); + throw CreateAIModelDependencyValidationException( + invalidAIModelException); } catch (HttpResponseTooManyRequestsException httpResponseTooManyRequestsException) { var excessiveCallAIModelException = - new ExcessiveCallAIModelException(httpResponseTooManyRequestsException); + new ExcessiveCallAIModelException( + message: "Excessive call error occurred, limit your calls.", + httpResponseTooManyRequestsException); - throw new AIModelDependencyValidationException(excessiveCallAIModelException); + throw CreateAIModelDependencyValidationException( + excessiveCallAIModelException); } catch (HttpResponseException httpResponseException) { var failedServerAIModelException = - new FailedServerAIModelException(httpResponseException); + new FailedServerAIModelException( + message: "Failed AI Model server error occurred, contact support", + httpResponseException); - throw new AIModelDependencyException(failedServerAIModelException); + throw CreateAIModelDependencyException( + failedServerAIModelException); } catch (Exception exception) { var failedAIModelServiceException = - new FailedAIModelServiceException(exception); + new FailedAIModelServiceException( + message: "Failed AI Model Service Exception occurred, please contact support for assistance.", + exception); - throw new AIModelServiceException( + throw CreateAIModelServiceException( failedAIModelServiceException); } } @@ -94,46 +119,92 @@ private async ValueTask> TryCatch(ReturningAIModelsFunction catch (HttpResponseUrlNotFoundException httpResponseUrlNotFoundException) { var invalidConfigurationAIModelException = - new InvalidConfigurationAIModelException(httpResponseUrlNotFoundException); + new InvalidConfigurationAIModelException( + message: "Invalid AI Model configuration error occurred, contact support.", + httpResponseUrlNotFoundException); - throw new AIModelDependencyException(invalidConfigurationAIModelException); + throw CreateAIModelDependencyException( + invalidConfigurationAIModelException); } catch (HttpResponseUnauthorizedException httpResponseUnauthorizedException) { var unauthorizedAIModelException = - new UnauthorizedAIModelException(httpResponseUnauthorizedException); + new UnauthorizedAIModelException( + message: "Unauthorized AI Model error occurred, fix errors and try again.", + httpResponseUnauthorizedException); - throw new AIModelDependencyException(unauthorizedAIModelException); + throw CreateAIModelDependencyException( + unauthorizedAIModelException); } catch (HttpResponseForbiddenException httpResponseForbiddenException) { var unauthorizedAIModelException = - new UnauthorizedAIModelException(httpResponseForbiddenException); + new UnauthorizedAIModelException( + message: "Unauthorized AI Model error occurred, fix errors and try again.", + httpResponseForbiddenException); - throw new AIModelDependencyException(unauthorizedAIModelException); + throw CreateAIModelDependencyException( + unauthorizedAIModelException); } catch (HttpResponseTooManyRequestsException httpResponseTooManyRequestsException) { var excessiveCallAIModelException = - new ExcessiveCallAIModelException(httpResponseTooManyRequestsException); + new ExcessiveCallAIModelException( + message: "Excessive call error occurred, limit your calls.", + httpResponseTooManyRequestsException); - throw new AIModelDependencyValidationException(excessiveCallAIModelException); + throw CreateAIModelDependencyValidationException( + excessiveCallAIModelException); } catch (HttpResponseException httpResponseException) { var failedServerAIModelException = - new FailedServerAIModelException(httpResponseException); + new FailedServerAIModelException( + message: "Failed AI Model server error occurred, contact support", + httpResponseException); - throw new AIModelDependencyException(failedServerAIModelException); + throw CreateAIModelDependencyException( + failedServerAIModelException); } catch (Exception exception) { var failedAIModelServiceException = - new FailedAIModelServiceException(exception); + new FailedAIModelServiceException( + message: "Failed AI Model Service Exception occurred, please contact support for assistance.", + exception); - throw new AIModelServiceException( + throw CreateAIModelServiceException( failedAIModelServiceException); } } + + private static AIModelValidationException CreateAIModelValidationException(Xeption innerException) + { + return new AIModelValidationException( + message: "AI Model validation error occurred, fix errors and try again.", + innerException); + } + + private static AIModelDependencyException CreateAIModelDependencyException(Xeption innerException) + { + return new AIModelDependencyException( + message: "AI Model dependency error occurred, contact support.", + innerException); + } + + private static AIModelDependencyValidationException + CreateAIModelDependencyValidationException(Xeption innerException) + { + return new AIModelDependencyValidationException( + message: "AI Model dependency validation error occurred, fix errors and try again.", + innerException); + } + + private static AIModelServiceException CreateAIModelServiceException(Xeption innerException) + { + return new AIModelServiceException( + message: "AI Model service error occurred, contact support.", + innerException); + } } } \ No newline at end of file diff --git a/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.Validations.cs b/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.Validations.cs index 5c8e67b5..24b5bef5 100644 --- a/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.Validations.cs +++ b/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.Validations.cs @@ -21,7 +21,9 @@ private static void ValidateAIModelName(string aiModelName) => private static void Validate(params (dynamic Rule, string Parameter)[] validations) { - var invalidAIModelException = new InvalidAIModelException(); + var invalidAIModelException = + new InvalidAIModelException( + message: "AI Model is invalid."); foreach ((dynamic rule, string parameter) in validations) { diff --git a/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.cs b/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.cs index a882c467..919097ee 100644 --- a/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.cs +++ b/Standard.AI.OpenAI/Services/Foundations/AIModels/AIModelService.cs @@ -8,7 +8,9 @@ using Standard.AI.OpenAI.Brokers.DateTimes; using Standard.AI.OpenAI.Brokers.OpenAIs; using Standard.AI.OpenAI.Models.Services.Foundations.AIModels; +using Standard.AI.OpenAI.Models.Services.Foundations.AIModels.Exceptions; using Standard.AI.OpenAI.Models.Services.Foundations.ExternalAIModels; +using Xeptions; namespace Standard.AI.OpenAI.Services.Foundations.AIModels {