org.wildfly.extension.ai.chat.OllamaChatLanguageModelProviderRegistrar 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.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_RETRIES;
import static org.wildfly.extension.ai.AIAttributeDefinitions.MODEL_NAME;
import static org.wildfly.extension.ai.AIAttributeDefinitions.TEMPERATURE;
import static org.wildfly.extension.ai.Capabilities.CHAT_MODEL_PROVIDER_CAPABILITY;
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.descriptions.ParentResourceDescriptionResolver;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.RuntimePackageDependency;
import static org.wildfly.extension.ai.AIAttributeDefinitions.RESPONSE_FORMAT;
import dev.langchain4j.model.chat.ChatLanguageModel;
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 OllamaChatLanguageModelProviderRegistrar implements ChildResourceDefinitionRegistrar {
public static final Collection ATTRIBUTES = List.of(BASE_URL, CONNECT_TIMEOUT,
LOG_REQUESTS, LOG_RESPONSES, MAX_RETRIES, MODEL_NAME, RESPONSE_FORMAT, TEMPERATURE);
private final ResourceRegistration registration;
private final ResourceDescriptor descriptor;
static final String NAME = "ollama-chat-model";
public static final PathElement PATH = PathElement.pathElement(NAME);
private final ValueExecutorRegistry registry = ValueExecutorRegistry.newInstance();
public OllamaChatLanguageModelProviderRegistrar(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 OllamaChatModelProviderServiceConfigurator(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.ollama"));
ManagementResourceRegistrar.of(this.descriptor).register(resourceRegistration);
return resourceRegistration;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy