org.wildfly.extension.ai.embedding.model.OllamaEmbeddingModelProviderRegistrar Maven / Gradle / Ivy
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.extension.ai.embedding.model;
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.MODEL_NAME;
import static org.wildfly.extension.ai.Capabilities.EMBEDDING_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.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 OllamaEmbeddingModelProviderRegistrar implements ChildResourceDefinitionRegistrar {
public static final Collection ATTRIBUTES = List.of(BASE_URL, CONNECT_TIMEOUT, LOG_REQUESTS, LOG_RESPONSES, MODEL_NAME);
private final ResourceRegistration registration;
private final ResourceDescriptor descriptor;
static final String NAME = "ollama-embedding-model";
public static final PathElement PATH = PathElement.pathElement(NAME);
public OllamaEmbeddingModelProviderRegistrar(ParentResourceDescriptionResolver parentResolver) {
this.registration = ResourceRegistration.of(PATH);
this.descriptor = ResourceDescriptor.builder(parentResolver.createChildResolver(PATH))
.addCapability(EMBEDDING_MODEL_PROVIDER_CAPABILITY)
.addAttributes(ATTRIBUTES)
.withRuntimeHandler(ResourceOperationRuntimeHandler.configureService(new OllamaEmbeddingModelProviderServiceConfigurator()))
.build();
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent, ManagementResourceRegistrationContext context) {
ResourceDefinition definition = ResourceDefinition.builder(this.registration, this.descriptor.getResourceDescriptionResolver()).build();
ManagementResourceRegistration resourceRegistration = parent.registerSubModel(definition);
ManagementResourceRegistrar.of(this.descriptor).register(resourceRegistration);
return resourceRegistration;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy