Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-16354625: Added required exceptions for each operation #18

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mule.mulechain</groupId>
<artifactId>mulechain-ai-connector</artifactId>
<version>0.2.13</version>
<version>0.2.14-SNAPSHOT</version>
<packaging>mule-extension</packaging>
<name>MuleChain</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package org.mule.extension.mulechain.internal.config;

import dev.langchain4j.model.chat.ChatLanguageModel;
import org.mule.extension.mulechain.internal.exception.config.ConfigValidationException;
import org.mule.extension.mulechain.internal.operation.LangchainEmbeddingStoresOperations;
import org.mule.extension.mulechain.internal.operation.LangchainImageModelsOperations;
import org.mule.extension.mulechain.internal.llm.type.LangchainLLMType;
Expand Down Expand Up @@ -141,7 +142,7 @@ private ChatLanguageModel createModel(ConfigExtractor configExtractor) {
if (llmMap.containsKey(type)) {
return llmMap.get(type).apply(configExtractor, this);
}
throw new IllegalArgumentException("LLM Type not supported: " + llmType);
throw new ConfigValidationException("LLM Type not supported: " + llmType);
}

@Override
Expand All @@ -151,7 +152,7 @@ public void initialise() throws InitialisationException {
configExtractor = configExtractorMap.get(config).apply(this);
model = createModel(configExtractor);
} else {
throw new IllegalArgumentException("Config Type not supported: " + configType);
throw new ConfigValidationException("Config Type not supported: " + configType);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.error;

import org.mule.runtime.extension.api.error.ErrorTypeDefinition;

public enum MuleChainErrorType implements ErrorTypeDefinition<MuleChainErrorType> {

INVALID_AUTHENTICATION, IO_EXCEPTION, TIME_OUT, RATE_LIMIT_OR_QUOTA_EXCEEDED;
AI_SERVICES_FAILURE, IMAGE_ANALYSIS_FAILURE, IMAGE_GENERATION_FAILURE, IMAGE_PROCESSING_FAILURE, FILE_HANDLING_FAILURE, RAG_FAILURE, EMBEDDING_OPERATIONS_FAILURE, TOOLS_OPERATION_FAILURE, VALIDATION_FAILURE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.error.provider;

import org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider;
import org.mule.runtime.extension.api.error.ErrorTypeDefinition;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import static java.util.Collections.unmodifiableSet;
import static org.mule.extension.mulechain.internal.error.MuleChainErrorType.AI_SERVICES_FAILURE;

public class AiServiceErrorTypeProvider implements ErrorTypeProvider {

@SuppressWarnings("rawtypes")
@Override
public Set<ErrorTypeDefinition> getErrorTypes() {
return unmodifiableSet(new HashSet<>(Collections.singletonList(AI_SERVICES_FAILURE)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.error.provider;

import org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider;
import org.mule.runtime.extension.api.error.ErrorTypeDefinition;

import java.util.HashSet;
import java.util.Set;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableSet;
import static org.mule.extension.mulechain.internal.error.MuleChainErrorType.AI_SERVICES_FAILURE;
import static org.mule.extension.mulechain.internal.error.MuleChainErrorType.EMBEDDING_OPERATIONS_FAILURE;
import static org.mule.extension.mulechain.internal.error.MuleChainErrorType.FILE_HANDLING_FAILURE;
import static org.mule.extension.mulechain.internal.error.MuleChainErrorType.RAG_FAILURE;
import static org.mule.extension.mulechain.internal.error.MuleChainErrorType.TOOLS_OPERATION_FAILURE;

public class EmbeddingErrorTypeProvider implements ErrorTypeProvider {

@SuppressWarnings("rawtypes")
@Override
public Set<ErrorTypeDefinition> getErrorTypes() {
return unmodifiableSet(new HashSet<>(asList(EMBEDDING_OPERATIONS_FAILURE, AI_SERVICES_FAILURE, RAG_FAILURE,
FILE_HANDLING_FAILURE, TOOLS_OPERATION_FAILURE)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.error.provider;

import org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider;
import org.mule.runtime.extension.api.error.ErrorTypeDefinition;

import java.util.HashSet;
import java.util.Set;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableSet;
import static org.mule.extension.mulechain.internal.error.MuleChainErrorType.FILE_HANDLING_FAILURE;
import static org.mule.extension.mulechain.internal.error.MuleChainErrorType.IMAGE_ANALYSIS_FAILURE;
import static org.mule.extension.mulechain.internal.error.MuleChainErrorType.IMAGE_GENERATION_FAILURE;
import static org.mule.extension.mulechain.internal.error.MuleChainErrorType.IMAGE_PROCESSING_FAILURE;

public class ImageErrorTypeProvider implements ErrorTypeProvider {

@SuppressWarnings("rawtypes")
@Override
public Set<ErrorTypeDefinition> getErrorTypes() {
return unmodifiableSet(new HashSet<>(asList(IMAGE_ANALYSIS_FAILURE, IMAGE_GENERATION_FAILURE, IMAGE_PROCESSING_FAILURE,
FILE_HANDLING_FAILURE)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class ChatException extends ModuleException {

public ChatException(String message, Exception exception) {
super(message, MuleChainErrorType.AI_SERVICES_FAILURE, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class FileHandlingException extends ModuleException {

public FileHandlingException(String message, Exception exception) {
super(message, MuleChainErrorType.FILE_HANDLING_FAILURE, exception);
}

public FileHandlingException(String message) {
super(message, MuleChainErrorType.FILE_HANDLING_FAILURE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class PromptTemplateException extends ModuleException {

public PromptTemplateException(String message, Exception exception) {
super(message, MuleChainErrorType.AI_SERVICES_FAILURE, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class SentimentAnalyzerException extends ModuleException {

public SentimentAnalyzerException(String message, Exception exception) {
super(message, MuleChainErrorType.AI_SERVICES_FAILURE, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception.config;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class ConfigValidationException extends ModuleException {

public ConfigValidationException(String message) {
super(message, MuleChainErrorType.VALIDATION_FAILURE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception.embedding;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class EmbeddingStoreOperationsException extends ModuleException {

public EmbeddingStoreOperationsException(String message, Exception exception) {
super(message, MuleChainErrorType.EMBEDDING_OPERATIONS_FAILURE, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception.embedding;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class RagException extends ModuleException {

public RagException(String message, Exception exception) {
super(message, MuleChainErrorType.RAG_FAILURE, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception.image;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class ImageAnalyzerException extends ModuleException {

public ImageAnalyzerException(String message, Exception exception) {
super(message, MuleChainErrorType.IMAGE_ANALYSIS_FAILURE, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception.image;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class ImageGenerationException extends ModuleException {

public ImageGenerationException(String message, Exception exception) {
super(message, MuleChainErrorType.IMAGE_GENERATION_FAILURE, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception.image;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class ImageProcessingException extends ModuleException {

public ImageProcessingException(String message, Exception exception) {
super(message, MuleChainErrorType.IMAGE_PROCESSING_FAILURE, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* (c) 2003-2024 MuleSoft, Inc. The software in this package is published under the terms of the Commercial Free Software license V.1 a copy of which has been included with this distribution in the LICENSE.md file.
*/
package org.mule.extension.mulechain.internal.exception.tools;

import org.mule.extension.mulechain.internal.error.MuleChainErrorType;
import org.mule.runtime.extension.api.exception.ModuleException;

public class ToolsOperationException extends ModuleException {

public ToolsOperationException(String message, Exception exception) {
super(message, MuleChainErrorType.TOOLS_OPERATION_FAILURE, exception);
}
}
Loading