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

com.cohere.api.requests.ClassifyRequest Maven / Gradle / Ivy

There is a newer version: 1.4.1
Show newest version
/**
 * This file was auto-generated by Fern from our API Definition.
 */
package com.cohere.api.requests;

import com.cohere.api.core.ObjectMappers;
import com.cohere.api.types.ClassifyExample;
import com.cohere.api.types.ClassifyRequestTruncate;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonDeserialize(builder = ClassifyRequest.Builder.class)
public final class ClassifyRequest {
    private final List inputs;

    private final Optional> examples;

    private final Optional model;

    private final Optional preset;

    private final Optional truncate;

    private final Map additionalProperties;

    private ClassifyRequest(
            List inputs,
            Optional> examples,
            Optional model,
            Optional preset,
            Optional truncate,
            Map additionalProperties) {
        this.inputs = inputs;
        this.examples = examples;
        this.model = model;
        this.preset = preset;
        this.truncate = truncate;
        this.additionalProperties = additionalProperties;
    }

    /**
     * @return A list of up to 96 texts to be classified. Each one must be a non-empty string.
     * There is, however, no consistent, universal limit to the length a particular input can be. We perform classification on the first x tokens of each input, and x varies depending on which underlying model is powering classification. The maximum token length for each model is listed in the "max tokens" column here.
     * Note: by default the truncate parameter is set to END, so tokens exceeding the limit will be automatically dropped. This behavior can be disabled by setting truncate to NONE, which will result in validation errors for longer texts.
     */
    @JsonProperty("inputs")
    public List getInputs() {
        return inputs;
    }

    /**
     * @return An array of examples to provide context to the model. Each example is a text string and its associated label/class. Each unique label requires at least 2 examples associated with it; the maximum number of examples is 2500, and each example has a maximum length of 512 tokens. The values should be structured as {text: "...",label: "..."}.
     * Note: Fine-tuned Models trained on classification examples don't require the examples parameter to be passed in explicitly.
     */
    @JsonProperty("examples")
    public Optional> getExamples() {
        return examples;
    }

    /**
     * @return The identifier of the model. Currently available models are embed-multilingual-v2.0, embed-english-light-v2.0, and embed-english-v2.0 (default). Smaller "light" models are faster, while larger models will perform better. Fine-tuned models can also be supplied with their full ID.
     */
    @JsonProperty("model")
    public Optional getModel() {
        return model;
    }

    /**
     * @return The ID of a custom playground preset. You can create presets in the playground. If you use a preset, all other parameters become optional, and any included parameters will override the preset's parameters.
     */
    @JsonProperty("preset")
    public Optional getPreset() {
        return preset;
    }

    /**
     * @return One of NONE|START|END to specify how the API will handle inputs longer than the maximum token length.
     * Passing START will discard the start of the input. END will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model.
     * If NONE is selected, when the input exceeds the maximum input token length an error will be returned.
     */
    @JsonProperty("truncate")
    public Optional getTruncate() {
        return truncate;
    }

    @java.lang.Override
    public boolean equals(Object other) {
        if (this == other) return true;
        return other instanceof ClassifyRequest && equalTo((ClassifyRequest) other);
    }

    @JsonAnyGetter
    public Map getAdditionalProperties() {
        return this.additionalProperties;
    }

    private boolean equalTo(ClassifyRequest other) {
        return inputs.equals(other.inputs)
                && examples.equals(other.examples)
                && model.equals(other.model)
                && preset.equals(other.preset)
                && truncate.equals(other.truncate);
    }

    @java.lang.Override
    public int hashCode() {
        return Objects.hash(this.inputs, this.examples, this.model, this.preset, this.truncate);
    }

    @java.lang.Override
    public String toString() {
        return ObjectMappers.stringify(this);
    }

    public static Builder builder() {
        return new Builder();
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static final class Builder {
        private List inputs = new ArrayList<>();

        private Optional> examples = Optional.empty();

        private Optional model = Optional.empty();

        private Optional preset = Optional.empty();

        private Optional truncate = Optional.empty();

        @JsonAnySetter
        private Map additionalProperties = new HashMap<>();

        private Builder() {}

        public Builder from(ClassifyRequest other) {
            inputs(other.getInputs());
            examples(other.getExamples());
            model(other.getModel());
            preset(other.getPreset());
            truncate(other.getTruncate());
            return this;
        }

        @JsonSetter(value = "inputs", nulls = Nulls.SKIP)
        public Builder inputs(List inputs) {
            this.inputs.clear();
            this.inputs.addAll(inputs);
            return this;
        }

        public Builder addInputs(String inputs) {
            this.inputs.add(inputs);
            return this;
        }

        public Builder addAllInputs(List inputs) {
            this.inputs.addAll(inputs);
            return this;
        }

        @JsonSetter(value = "examples", nulls = Nulls.SKIP)
        public Builder examples(Optional> examples) {
            this.examples = examples;
            return this;
        }

        public Builder examples(List examples) {
            this.examples = Optional.of(examples);
            return this;
        }

        @JsonSetter(value = "model", nulls = Nulls.SKIP)
        public Builder model(Optional model) {
            this.model = model;
            return this;
        }

        public Builder model(String model) {
            this.model = Optional.of(model);
            return this;
        }

        @JsonSetter(value = "preset", nulls = Nulls.SKIP)
        public Builder preset(Optional preset) {
            this.preset = preset;
            return this;
        }

        public Builder preset(String preset) {
            this.preset = Optional.of(preset);
            return this;
        }

        @JsonSetter(value = "truncate", nulls = Nulls.SKIP)
        public Builder truncate(Optional truncate) {
            this.truncate = truncate;
            return this;
        }

        public Builder truncate(ClassifyRequestTruncate truncate) {
            this.truncate = Optional.of(truncate);
            return this;
        }

        public ClassifyRequest build() {
            return new ClassifyRequest(inputs, examples, model, preset, truncate, additionalProperties);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy