org.wildfly.extension.ai.chat.MistralAIChatLanguageModelProviderRegistrar Maven / Gradle / Ivy
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.extension.ai.chat;
import static org.wildfly.extension.ai.AIAttributeDefinitions.API_KEY;
import static org.wildfly.extension.ai.AIAttributeDefinitions.BASE_URL;
import static org.wildfly.extension.ai.AIAttributeDefinitions.CONNECT_TIMEOUT;
import static org.wildfly.extension.ai.AIAttributeDefinitions.LOG_REQUESTS;
import static org.wildfly.extension.ai.AIAttributeDefinitions.LOG_RESPONSES;
import static org.wildfly.extension.ai.AIAttributeDefinitions.MAX_TOKEN;
import static org.wildfly.extension.ai.AIAttributeDefinitions.MODEL_NAME;
import static org.wildfly.extension.ai.AIAttributeDefinitions.RESPONSE_FORMAT;
import static org.wildfly.extension.ai.AIAttributeDefinitions.TEMPERATURE;
import static org.wildfly.extension.ai.AIAttributeDefinitions.TOP_P;
import static org.wildfly.extension.ai.Capabilities.CHAT_MODEL_PROVIDER_CAPABILITY;
import dev.langchain4j.model.chat.ChatLanguageModel;
import java.util.Collection;
import java.util.List;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.ResourceRegistration;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.RuntimePackageDependency;
import org.jboss.dmr.ModelType;
import org.wildfly.service.capture.ValueExecutorRegistry;
import org.wildfly.subsystem.resource.ChildResourceDefinitionRegistrar;
import org.wildfly.subsystem.resource.ManagementResourceRegistrar;
import org.wildfly.subsystem.resource.ManagementResourceRegistrationContext;
import org.wildfly.subsystem.resource.ResourceDescriptor;
import org.wildfly.subsystem.resource.operation.ResourceOperationRuntimeHandler;
public class MistralAIChatLanguageModelProviderRegistrar implements ChildResourceDefinitionRegistrar {
public static final SimpleAttributeDefinition RANDOM_SEED = new SimpleAttributeDefinitionBuilder("random-seed", ModelType.INT, true)
.setAllowExpression(true)
.build();
public static final SimpleAttributeDefinition SAFE_PROMPT = SimpleAttributeDefinitionBuilder.create("safe-prompt", ModelType.BOOLEAN, true)
.setAllowExpression(true)
.build();
public static final Collection ATTRIBUTES = List.of(API_KEY, BASE_URL, CONNECT_TIMEOUT,
LOG_REQUESTS, LOG_RESPONSES, MAX_TOKEN, MODEL_NAME, RANDOM_SEED, RESPONSE_FORMAT, SAFE_PROMPT, TEMPERATURE, TOP_P);
private final ResourceRegistration registration;
private final ResourceDescriptor descriptor;
static final String NAME = "mistral-ai-chat-model";
public static final PathElement PATH = PathElement.pathElement(NAME);
private final ValueExecutorRegistry registry = ValueExecutorRegistry.newInstance();
public MistralAIChatLanguageModelProviderRegistrar(ParentResourceDescriptionResolver parentResolver) {
this.registration = ResourceRegistration.of(PATH);
this.descriptor = ResourceDescriptor.builder(parentResolver.createChildResolver(PATH))
.addCapability(CHAT_MODEL_PROVIDER_CAPABILITY)
.addAttributes(ATTRIBUTES)
.withRuntimeHandler(ResourceOperationRuntimeHandler.configureService(new MistralAIChatModelProviderServiceConfigurator(registry)))
.build();
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent, ManagementResourceRegistrationContext context) {
ResourceDefinition definition = ResourceDefinition.builder(this.registration, this.descriptor.getResourceDescriptionResolver()).build();
ManagementResourceRegistration resourceRegistration = parent.registerSubModel(definition);
ChatModelConnectionCheckerOperationHandler.register(resourceRegistration, descriptor, registry);
resourceRegistration.registerAdditionalRuntimePackages(RuntimePackageDependency.required("dev.langchain4j.mistral-ai"));
ManagementResourceRegistrar.of(this.descriptor).register(resourceRegistration);
return resourceRegistration;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy