All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.semantickernel.semanticfunctions.AggregatorPromptTemplateFactory Maven / Gradle / Ivy

There is a newer version: 1.3.0
Show newest version
// Copyright (c) Microsoft. All rights reserved.
package com.microsoft.semantickernel.semanticfunctions;

import java.util.ArrayList;
import java.util.List;
import reactor.util.annotation.NonNull;

/**
 * An collection of {@link PromptTemplateFactory} instances. The factory will try to create a
 * {@link PromptTemplate} using each factory in the collection until one is successful.
 */
public class AggregatorPromptTemplateFactory implements PromptTemplateFactory {

    private final List templateFactories;

    /**
     * Creates a new instance of {@link AggregatorPromptTemplateFactory}.
     *
     * @param templateFactories the factories to aggregate
     */
    public AggregatorPromptTemplateFactory(List templateFactories) {
        this.templateFactories = new ArrayList<>(templateFactories);
    }

    @Override
    public PromptTemplate tryCreate(@NonNull PromptTemplateConfig templateConfig) {
        for (PromptTemplateFactory factory : templateFactories) {
            try {
                return factory.tryCreate(templateConfig);
            } catch (UnknownTemplateFormatException ignored) {
                // No-op
            }
        }

        throw new UnknownTemplateFormatException(templateConfig.getTemplateFormat());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy