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

ai.vespa.llm.completion.Completion Maven / Gradle / Ivy

Go to download

Library for use in Java components of Vespa. Shared code which do not fit anywhere else.

There is a newer version: 8.441.21
Show newest version
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.llm.completion;

import com.yahoo.api.annotations.Beta;

import java.util.Objects;

/**
 * A completion from a language model.
 *
 * @author bratseth
 */
@Beta
public record Completion(String text, FinishReason finishReason) {

    public enum FinishReason {

        /** The maximum length of a completion was reached. */
        length,

        /** The completion is the predicted ending of the prompt. */
        stop,

        /** The completion is not finished yet, more tokens are incoming. */
        none,

        /** An error occurred while generating the completion */
        error
    }

    public Completion(String text, FinishReason finishReason) {
        this.text = Objects.requireNonNull(text);
        this.finishReason = Objects.requireNonNull(finishReason);
    }

    /** Returns the generated text completion. */
    public String text() { return text; }

    /** Returns the reason this completion ended. */
    public FinishReason finishReason() { return finishReason; }

    public static Completion from(String text) {
        return from(text, FinishReason.stop);
    }

    public static Completion from(String text, FinishReason reason) {
        return new Completion(text, reason);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy