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

com.cohere.api.requests.ChatRequest 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.ChatConnector;
import com.cohere.api.types.ChatRequestCitationQuality;
import com.cohere.api.types.ChatRequestPromptTruncation;
import com.cohere.api.types.Message;
import com.cohere.api.types.Tool;
import com.cohere.api.types.ToolResult;
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.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonDeserialize(builder = ChatRequest.Builder.class)
public final class ChatRequest {
    private final String message;

    private final Optional model;

    private final Optional preamble;

    private final Optional> chatHistory;

    private final Optional conversationId;

    private final Optional promptTruncation;

    private final Optional> connectors;

    private final Optional searchQueriesOnly;

    private final Optional>> documents;

    private final Optional citationQuality;

    private final Optional temperature;

    private final Optional maxTokens;

    private final Optional maxInputTokens;

    private final Optional k;

    private final Optional p;

    private final Optional seed;

    private final Optional> stopSequences;

    private final Optional frequencyPenalty;

    private final Optional presencePenalty;

    private final Optional rawPrompting;

    private final Optional returnPrompt;

    private final Optional> tools;

    private final Optional> toolResults;

    private final Map additionalProperties;

    private ChatRequest(
            String message,
            Optional model,
            Optional preamble,
            Optional> chatHistory,
            Optional conversationId,
            Optional promptTruncation,
            Optional> connectors,
            Optional searchQueriesOnly,
            Optional>> documents,
            Optional citationQuality,
            Optional temperature,
            Optional maxTokens,
            Optional maxInputTokens,
            Optional k,
            Optional p,
            Optional seed,
            Optional> stopSequences,
            Optional frequencyPenalty,
            Optional presencePenalty,
            Optional rawPrompting,
            Optional returnPrompt,
            Optional> tools,
            Optional> toolResults,
            Map additionalProperties) {
        this.message = message;
        this.model = model;
        this.preamble = preamble;
        this.chatHistory = chatHistory;
        this.conversationId = conversationId;
        this.promptTruncation = promptTruncation;
        this.connectors = connectors;
        this.searchQueriesOnly = searchQueriesOnly;
        this.documents = documents;
        this.citationQuality = citationQuality;
        this.temperature = temperature;
        this.maxTokens = maxTokens;
        this.maxInputTokens = maxInputTokens;
        this.k = k;
        this.p = p;
        this.seed = seed;
        this.stopSequences = stopSequences;
        this.frequencyPenalty = frequencyPenalty;
        this.presencePenalty = presencePenalty;
        this.rawPrompting = rawPrompting;
        this.returnPrompt = returnPrompt;
        this.tools = tools;
        this.toolResults = toolResults;
        this.additionalProperties = additionalProperties;
    }

    /**
     * @return Text input for the model to respond to.
     * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments
     */
    @JsonProperty("message")
    public String getMessage() {
        return message;
    }

    /**
     * @return Defaults to command-r-plus.
     * 

The name of a compatible Cohere model or the ID of a fine-tuned model. * Compatible Deployments: Cohere Platform, Private Deployments

*/ @JsonProperty("model") public Optional getModel() { return model; } /** * @return Defaults to false. *

When true, the response will be a JSON stream of events. The final event will contain the complete response, and will have an event_type of "stream-end".

*

Streaming is beneficial for user interfaces that render the contents of the response piece by piece, as it gets generated. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("stream") public Boolean getStream() { return false; } /** * @return When specified, the default Cohere preamble will be replaced with the provided one. Preambles are a part of the prompt used to adjust the model's overall behavior and conversation style, and use the SYSTEM role. *

The SYSTEM role is also used for the contents of the optional chat_history= parameter. When used with the chat_history= parameter it adds content throughout a conversation. Conversely, when used with the preamble= parameter it adds content at the start of the conversation only. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("preamble") public Optional getPreamble() { return preamble; } /** * @return A list of previous messages between the user and the model, giving the model conversational context for responding to the user's message. *

Each item represents a single message in the chat history, excluding the current user turn. It has two properties: role and message. The role identifies the sender (CHATBOT, SYSTEM, or USER), while the message contains the text content.

*

The chat_history parameter should not be used for SYSTEM messages in most cases. Instead, to add a SYSTEM role message at the beginning of a conversation, the preamble parameter should be used. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("chat_history") public Optional> getChatHistory() { return chatHistory; } /** * @return An alternative to chat_history. *

Providing a conversation_id creates or resumes a persisted conversation with the specified ID. The ID can be any non empty string. * Compatible Deployments: Cohere Platform

*/ @JsonProperty("conversation_id") public Optional getConversationId() { return conversationId; } /** * @return Defaults to AUTO when connectors are specified and OFF in all other cases. *

Dictates how the prompt will be constructed.

*

With prompt_truncation set to "AUTO", some elements from chat_history and documents will be dropped in an attempt to construct a prompt that fits within the model's context length limit. During this process the order of the documents and chat history will be changed and ranked by relevance.

*

With prompt_truncation set to "AUTO_PRESERVE_ORDER", some elements from chat_history and documents will be dropped in an attempt to construct a prompt that fits within the model's context length limit. During this process the order of the documents and chat history will be preserved as they are inputted into the API.

*

With prompt_truncation set to "OFF", no elements will be dropped. If the sum of the inputs exceeds the model's context length limit, a TooManyTokens error will be returned. * Compatible Deployments: Cohere Platform Only AUTO_PRESERVE_ORDER: Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("prompt_truncation") public Optional getPromptTruncation() { return promptTruncation; } /** * @return Accepts {"id": "web-search"}, and/or the "id" for a custom connector, if you've created one. *

When specified, the model's reply will be enriched with information found by quering each of the connectors (RAG). * Compatible Deployments: Cohere Platform

*/ @JsonProperty("connectors") public Optional> getConnectors() { return connectors; } /** * @return Defaults to false. *

When true, the response will only contain a list of generated search queries, but no search will take place, and no reply from the model to the user's message will be generated. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("search_queries_only") public Optional getSearchQueriesOnly() { return searchQueriesOnly; } /** * @return A list of relevant documents that the model can cite to generate a more accurate reply. Each document is a string-string dictionary. *

Example: * [ { "title": "Tall penguins", "text": "Emperor penguins are the tallest." }, { "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica." }, ]

*

Keys and values from each document will be serialized to a string and passed to the model. The resulting generation will include citations that reference some of these documents.

*

Some suggested keys are "text", "author", and "date". For better generation quality, it is recommended to keep the total word count of the strings in the dictionary to under 300 words.

*

An id field (string) can be optionally supplied to identify the document in the citations. This field will not be passed to the model.

*

An _excludes field (array of strings) can be optionally supplied to omit some key-value pairs from being shown to the model. The omitted fields will still show up in the citation object. The "_excludes" field will not be passed to the model.

*

See 'Document Mode' in the guide for more information. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("documents") public Optional>> getDocuments() { return documents; } /** * @return Defaults to "accurate". *

Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results or "fast" results. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("citation_quality") public Optional getCitationQuality() { return citationQuality; } /** * @return Defaults to 0.3. *

A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations, and higher temperatures mean more random generations.

*

Randomness can be further maximized by increasing the value of the p parameter. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("temperature") public Optional getTemperature() { return temperature; } /** * @return The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments */ @JsonProperty("max_tokens") public Optional getMaxTokens() { return maxTokens; } /** * @return The maximum number of input tokens to send to the model. If not specified, max_input_tokens is the model's context length limit minus a small buffer. *

Input will be truncated according to the prompt_truncation parameter. * Compatible Deployments: Cohere Platform

*/ @JsonProperty("max_input_tokens") public Optional getMaxInputTokens() { return maxInputTokens; } /** * @return Ensures only the top k most likely tokens are considered for generation at each step. * Defaults to 0, min value of 0, max value of 500. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments */ @JsonProperty("k") public Optional getK() { return k; } /** * @return Ensures that only the most likely tokens, with total probability mass of p, are considered for generation at each step. If both k and p are enabled, p acts after k. * Defaults to 0.75. min value of 0.01, max value of 0.99. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments */ @JsonProperty("p") public Optional getP() { return p; } /** * @return If specified, the backend will make a best effort to sample tokens * deterministically, such that repeated requests with the same * seed and parameters should return the same result. However, * determinism cannot be totally guaranteed. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments */ @JsonProperty("seed") public Optional getSeed() { return seed; } /** * @return A list of up to 5 strings that the model will use to stop generation. If the model generates a string that matches any of the strings in the list, it will stop generating tokens and return the generated text up to that point not including the stop sequence. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments */ @JsonProperty("stop_sequences") public Optional> getStopSequences() { return stopSequences; } /** * @return Defaults to 0.0, min value of 0.0, max value of 1.0. *

Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("frequency_penalty") public Optional getFrequencyPenalty() { return frequencyPenalty; } /** * @return Defaults to 0.0, min value of 0.0, max value of 1.0. *

Used to reduce repetitiveness of generated tokens. Similar to frequency_penalty, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("presence_penalty") public Optional getPresencePenalty() { return presencePenalty; } /** * @return When enabled, the user's prompt will be sent to the model without * any pre-processing. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments */ @JsonProperty("raw_prompting") public Optional getRawPrompting() { return rawPrompting; } /** * @return The prompt is returned in the prompt response field when this is enabled. */ @JsonProperty("return_prompt") public Optional getReturnPrompt() { return returnPrompt; } /** * @return A list of available tools (functions) that the model may suggest invoking before producing a text response. *

When tools is passed (without tool_results), the text field in the response will be "" and the tool_calls field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the tool_calls array will be empty. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("tools") public Optional> getTools() { return tools; } /** * @return A list of results from invoking tools recommended by the model in the previous chat turn. Results are used to produce a text response and will be referenced in citations. When using tool_results, tools must be passed as well. * Each tool_result contains information about how it was invoked, as well as a list of outputs in the form of dictionaries. *

Note: outputs must be a list of objects. If your tool returns a single object (eg {"status": 200}), make sure to wrap it in a list.

*
tool_results = [
     *   {
     *     "call": {
     *       "name": <tool name>,
     *       "parameters": {
     *         <param name>: <param value>
     *       }
     *     },
     *     "outputs": [{
     *       <key>: <value>
     *     }]
     *   },
     *   ...
     * ]
     * 
*

Note: Chat calls with tool_results should not be included in the Chat history to avoid duplication of the message text. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

*/ @JsonProperty("tool_results") public Optional> getToolResults() { return toolResults; } @java.lang.Override public boolean equals(Object other) { if (this == other) return true; return other instanceof ChatRequest && equalTo((ChatRequest) other); } @JsonAnyGetter public Map getAdditionalProperties() { return this.additionalProperties; } private boolean equalTo(ChatRequest other) { return message.equals(other.message) && model.equals(other.model) && preamble.equals(other.preamble) && chatHistory.equals(other.chatHistory) && conversationId.equals(other.conversationId) && promptTruncation.equals(other.promptTruncation) && connectors.equals(other.connectors) && searchQueriesOnly.equals(other.searchQueriesOnly) && documents.equals(other.documents) && citationQuality.equals(other.citationQuality) && temperature.equals(other.temperature) && maxTokens.equals(other.maxTokens) && maxInputTokens.equals(other.maxInputTokens) && k.equals(other.k) && p.equals(other.p) && seed.equals(other.seed) && stopSequences.equals(other.stopSequences) && frequencyPenalty.equals(other.frequencyPenalty) && presencePenalty.equals(other.presencePenalty) && rawPrompting.equals(other.rawPrompting) && returnPrompt.equals(other.returnPrompt) && tools.equals(other.tools) && toolResults.equals(other.toolResults); } @java.lang.Override public int hashCode() { return Objects.hash( this.message, this.model, this.preamble, this.chatHistory, this.conversationId, this.promptTruncation, this.connectors, this.searchQueriesOnly, this.documents, this.citationQuality, this.temperature, this.maxTokens, this.maxInputTokens, this.k, this.p, this.seed, this.stopSequences, this.frequencyPenalty, this.presencePenalty, this.rawPrompting, this.returnPrompt, this.tools, this.toolResults); } @java.lang.Override public String toString() { return ObjectMappers.stringify(this); } public static MessageStage builder() { return new Builder(); } public interface MessageStage { _FinalStage message(String message); Builder from(ChatRequest other); } public interface _FinalStage { ChatRequest build(); _FinalStage model(Optional model); _FinalStage model(String model); _FinalStage preamble(Optional preamble); _FinalStage preamble(String preamble); _FinalStage chatHistory(Optional> chatHistory); _FinalStage chatHistory(List chatHistory); _FinalStage conversationId(Optional conversationId); _FinalStage conversationId(String conversationId); _FinalStage promptTruncation(Optional promptTruncation); _FinalStage promptTruncation(ChatRequestPromptTruncation promptTruncation); _FinalStage connectors(Optional> connectors); _FinalStage connectors(List connectors); _FinalStage searchQueriesOnly(Optional searchQueriesOnly); _FinalStage searchQueriesOnly(Boolean searchQueriesOnly); _FinalStage documents(Optional>> documents); _FinalStage documents(List> documents); _FinalStage citationQuality(Optional citationQuality); _FinalStage citationQuality(ChatRequestCitationQuality citationQuality); _FinalStage temperature(Optional temperature); _FinalStage temperature(Double temperature); _FinalStage maxTokens(Optional maxTokens); _FinalStage maxTokens(Integer maxTokens); _FinalStage maxInputTokens(Optional maxInputTokens); _FinalStage maxInputTokens(Integer maxInputTokens); _FinalStage k(Optional k); _FinalStage k(Integer k); _FinalStage p(Optional p); _FinalStage p(Double p); _FinalStage seed(Optional seed); _FinalStage seed(Double seed); _FinalStage stopSequences(Optional> stopSequences); _FinalStage stopSequences(List stopSequences); _FinalStage frequencyPenalty(Optional frequencyPenalty); _FinalStage frequencyPenalty(Double frequencyPenalty); _FinalStage presencePenalty(Optional presencePenalty); _FinalStage presencePenalty(Double presencePenalty); _FinalStage rawPrompting(Optional rawPrompting); _FinalStage rawPrompting(Boolean rawPrompting); _FinalStage returnPrompt(Optional returnPrompt); _FinalStage returnPrompt(Boolean returnPrompt); _FinalStage tools(Optional> tools); _FinalStage tools(List tools); _FinalStage toolResults(Optional> toolResults); _FinalStage toolResults(List toolResults); } @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder implements MessageStage, _FinalStage { private String message; private Optional> toolResults = Optional.empty(); private Optional> tools = Optional.empty(); private Optional returnPrompt = Optional.empty(); private Optional rawPrompting = Optional.empty(); private Optional presencePenalty = Optional.empty(); private Optional frequencyPenalty = Optional.empty(); private Optional> stopSequences = Optional.empty(); private Optional seed = Optional.empty(); private Optional p = Optional.empty(); private Optional k = Optional.empty(); private Optional maxInputTokens = Optional.empty(); private Optional maxTokens = Optional.empty(); private Optional temperature = Optional.empty(); private Optional citationQuality = Optional.empty(); private Optional>> documents = Optional.empty(); private Optional searchQueriesOnly = Optional.empty(); private Optional> connectors = Optional.empty(); private Optional promptTruncation = Optional.empty(); private Optional conversationId = Optional.empty(); private Optional> chatHistory = Optional.empty(); private Optional preamble = Optional.empty(); private Optional model = Optional.empty(); @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @java.lang.Override public Builder from(ChatRequest other) { message(other.getMessage()); model(other.getModel()); preamble(other.getPreamble()); chatHistory(other.getChatHistory()); conversationId(other.getConversationId()); promptTruncation(other.getPromptTruncation()); connectors(other.getConnectors()); searchQueriesOnly(other.getSearchQueriesOnly()); documents(other.getDocuments()); citationQuality(other.getCitationQuality()); temperature(other.getTemperature()); maxTokens(other.getMaxTokens()); maxInputTokens(other.getMaxInputTokens()); k(other.getK()); p(other.getP()); seed(other.getSeed()); stopSequences(other.getStopSequences()); frequencyPenalty(other.getFrequencyPenalty()); presencePenalty(other.getPresencePenalty()); rawPrompting(other.getRawPrompting()); returnPrompt(other.getReturnPrompt()); tools(other.getTools()); toolResults(other.getToolResults()); return this; } /** *

Text input for the model to respond to. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override @JsonSetter("message") public _FinalStage message(String message) { this.message = message; return this; } /** *

A list of results from invoking tools recommended by the model in the previous chat turn. Results are used to produce a text response and will be referenced in citations. When using tool_results, tools must be passed as well. * Each tool_result contains information about how it was invoked, as well as a list of outputs in the form of dictionaries.

*

Note: outputs must be a list of objects. If your tool returns a single object (eg {"status": 200}), make sure to wrap it in a list.

*
tool_results = [
         *   {
         *     "call": {
         *       "name": <tool name>,
         *       "parameters": {
         *         <param name>: <param value>
         *       }
         *     },
         *     "outputs": [{
         *       <key>: <value>
         *     }]
         *   },
         *   ...
         * ]
         * 
*

Note: Chat calls with tool_results should not be included in the Chat history to avoid duplication of the message text. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage toolResults(List toolResults) { this.toolResults = Optional.of(toolResults); return this; } @java.lang.Override @JsonSetter(value = "tool_results", nulls = Nulls.SKIP) public _FinalStage toolResults(Optional> toolResults) { this.toolResults = toolResults; return this; } /** *

A list of available tools (functions) that the model may suggest invoking before producing a text response.

*

When tools is passed (without tool_results), the text field in the response will be "" and the tool_calls field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the tool_calls array will be empty. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage tools(List tools) { this.tools = Optional.of(tools); return this; } @java.lang.Override @JsonSetter(value = "tools", nulls = Nulls.SKIP) public _FinalStage tools(Optional> tools) { this.tools = tools; return this; } /** *

The prompt is returned in the prompt response field when this is enabled.

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage returnPrompt(Boolean returnPrompt) { this.returnPrompt = Optional.of(returnPrompt); return this; } @java.lang.Override @JsonSetter(value = "return_prompt", nulls = Nulls.SKIP) public _FinalStage returnPrompt(Optional returnPrompt) { this.returnPrompt = returnPrompt; return this; } /** *

When enabled, the user's prompt will be sent to the model without * any pre-processing. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage rawPrompting(Boolean rawPrompting) { this.rawPrompting = Optional.of(rawPrompting); return this; } @java.lang.Override @JsonSetter(value = "raw_prompting", nulls = Nulls.SKIP) public _FinalStage rawPrompting(Optional rawPrompting) { this.rawPrompting = rawPrompting; return this; } /** *

Defaults to 0.0, min value of 0.0, max value of 1.0.

*

Used to reduce repetitiveness of generated tokens. Similar to frequency_penalty, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage presencePenalty(Double presencePenalty) { this.presencePenalty = Optional.of(presencePenalty); return this; } @java.lang.Override @JsonSetter(value = "presence_penalty", nulls = Nulls.SKIP) public _FinalStage presencePenalty(Optional presencePenalty) { this.presencePenalty = presencePenalty; return this; } /** *

Defaults to 0.0, min value of 0.0, max value of 1.0.

*

Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage frequencyPenalty(Double frequencyPenalty) { this.frequencyPenalty = Optional.of(frequencyPenalty); return this; } @java.lang.Override @JsonSetter(value = "frequency_penalty", nulls = Nulls.SKIP) public _FinalStage frequencyPenalty(Optional frequencyPenalty) { this.frequencyPenalty = frequencyPenalty; return this; } /** *

A list of up to 5 strings that the model will use to stop generation. If the model generates a string that matches any of the strings in the list, it will stop generating tokens and return the generated text up to that point not including the stop sequence. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage stopSequences(List stopSequences) { this.stopSequences = Optional.of(stopSequences); return this; } @java.lang.Override @JsonSetter(value = "stop_sequences", nulls = Nulls.SKIP) public _FinalStage stopSequences(Optional> stopSequences) { this.stopSequences = stopSequences; return this; } /** *

If specified, the backend will make a best effort to sample tokens * deterministically, such that repeated requests with the same * seed and parameters should return the same result. However, * determinism cannot be totally guaranteed. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage seed(Double seed) { this.seed = Optional.of(seed); return this; } @java.lang.Override @JsonSetter(value = "seed", nulls = Nulls.SKIP) public _FinalStage seed(Optional seed) { this.seed = seed; return this; } /** *

Ensures that only the most likely tokens, with total probability mass of p, are considered for generation at each step. If both k and p are enabled, p acts after k. * Defaults to 0.75. min value of 0.01, max value of 0.99. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage p(Double p) { this.p = Optional.of(p); return this; } @java.lang.Override @JsonSetter(value = "p", nulls = Nulls.SKIP) public _FinalStage p(Optional p) { this.p = p; return this; } /** *

Ensures only the top k most likely tokens are considered for generation at each step. * Defaults to 0, min value of 0, max value of 500. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage k(Integer k) { this.k = Optional.of(k); return this; } @java.lang.Override @JsonSetter(value = "k", nulls = Nulls.SKIP) public _FinalStage k(Optional k) { this.k = k; return this; } /** *

The maximum number of input tokens to send to the model. If not specified, max_input_tokens is the model's context length limit minus a small buffer.

*

Input will be truncated according to the prompt_truncation parameter. * Compatible Deployments: Cohere Platform

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage maxInputTokens(Integer maxInputTokens) { this.maxInputTokens = Optional.of(maxInputTokens); return this; } @java.lang.Override @JsonSetter(value = "max_input_tokens", nulls = Nulls.SKIP) public _FinalStage maxInputTokens(Optional maxInputTokens) { this.maxInputTokens = maxInputTokens; return this; } /** *

The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage maxTokens(Integer maxTokens) { this.maxTokens = Optional.of(maxTokens); return this; } @java.lang.Override @JsonSetter(value = "max_tokens", nulls = Nulls.SKIP) public _FinalStage maxTokens(Optional maxTokens) { this.maxTokens = maxTokens; return this; } /** *

Defaults to 0.3.

*

A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations, and higher temperatures mean more random generations.

*

Randomness can be further maximized by increasing the value of the p parameter. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage temperature(Double temperature) { this.temperature = Optional.of(temperature); return this; } @java.lang.Override @JsonSetter(value = "temperature", nulls = Nulls.SKIP) public _FinalStage temperature(Optional temperature) { this.temperature = temperature; return this; } /** *

Defaults to "accurate".

*

Dictates the approach taken to generating citations as part of the RAG flow by allowing the user to specify whether they want "accurate" results or "fast" results. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage citationQuality(ChatRequestCitationQuality citationQuality) { this.citationQuality = Optional.of(citationQuality); return this; } @java.lang.Override @JsonSetter(value = "citation_quality", nulls = Nulls.SKIP) public _FinalStage citationQuality(Optional citationQuality) { this.citationQuality = citationQuality; return this; } /** *

A list of relevant documents that the model can cite to generate a more accurate reply. Each document is a string-string dictionary.

*

Example: * [ { "title": "Tall penguins", "text": "Emperor penguins are the tallest." }, { "title": "Penguin habitats", "text": "Emperor penguins only live in Antarctica." }, ]

*

Keys and values from each document will be serialized to a string and passed to the model. The resulting generation will include citations that reference some of these documents.

*

Some suggested keys are "text", "author", and "date". For better generation quality, it is recommended to keep the total word count of the strings in the dictionary to under 300 words.

*

An id field (string) can be optionally supplied to identify the document in the citations. This field will not be passed to the model.

*

An _excludes field (array of strings) can be optionally supplied to omit some key-value pairs from being shown to the model. The omitted fields will still show up in the citation object. The "_excludes" field will not be passed to the model.

*

See 'Document Mode' in the guide for more information. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage documents(List> documents) { this.documents = Optional.of(documents); return this; } @java.lang.Override @JsonSetter(value = "documents", nulls = Nulls.SKIP) public _FinalStage documents(Optional>> documents) { this.documents = documents; return this; } /** *

Defaults to false.

*

When true, the response will only contain a list of generated search queries, but no search will take place, and no reply from the model to the user's message will be generated. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage searchQueriesOnly(Boolean searchQueriesOnly) { this.searchQueriesOnly = Optional.of(searchQueriesOnly); return this; } @java.lang.Override @JsonSetter(value = "search_queries_only", nulls = Nulls.SKIP) public _FinalStage searchQueriesOnly(Optional searchQueriesOnly) { this.searchQueriesOnly = searchQueriesOnly; return this; } /** *

Accepts {"id": "web-search"}, and/or the "id" for a custom connector, if you've created one.

*

When specified, the model's reply will be enriched with information found by quering each of the connectors (RAG). * Compatible Deployments: Cohere Platform

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage connectors(List connectors) { this.connectors = Optional.of(connectors); return this; } @java.lang.Override @JsonSetter(value = "connectors", nulls = Nulls.SKIP) public _FinalStage connectors(Optional> connectors) { this.connectors = connectors; return this; } /** *

Defaults to AUTO when connectors are specified and OFF in all other cases.

*

Dictates how the prompt will be constructed.

*

With prompt_truncation set to "AUTO", some elements from chat_history and documents will be dropped in an attempt to construct a prompt that fits within the model's context length limit. During this process the order of the documents and chat history will be changed and ranked by relevance.

*

With prompt_truncation set to "AUTO_PRESERVE_ORDER", some elements from chat_history and documents will be dropped in an attempt to construct a prompt that fits within the model's context length limit. During this process the order of the documents and chat history will be preserved as they are inputted into the API.

*

With prompt_truncation set to "OFF", no elements will be dropped. If the sum of the inputs exceeds the model's context length limit, a TooManyTokens error will be returned. * Compatible Deployments: Cohere Platform Only AUTO_PRESERVE_ORDER: Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage promptTruncation(ChatRequestPromptTruncation promptTruncation) { this.promptTruncation = Optional.of(promptTruncation); return this; } @java.lang.Override @JsonSetter(value = "prompt_truncation", nulls = Nulls.SKIP) public _FinalStage promptTruncation(Optional promptTruncation) { this.promptTruncation = promptTruncation; return this; } /** *

An alternative to chat_history.

*

Providing a conversation_id creates or resumes a persisted conversation with the specified ID. The ID can be any non empty string. * Compatible Deployments: Cohere Platform

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage conversationId(String conversationId) { this.conversationId = Optional.of(conversationId); return this; } @java.lang.Override @JsonSetter(value = "conversation_id", nulls = Nulls.SKIP) public _FinalStage conversationId(Optional conversationId) { this.conversationId = conversationId; return this; } /** *

A list of previous messages between the user and the model, giving the model conversational context for responding to the user's message.

*

Each item represents a single message in the chat history, excluding the current user turn. It has two properties: role and message. The role identifies the sender (CHATBOT, SYSTEM, or USER), while the message contains the text content.

*

The chat_history parameter should not be used for SYSTEM messages in most cases. Instead, to add a SYSTEM role message at the beginning of a conversation, the preamble parameter should be used. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage chatHistory(List chatHistory) { this.chatHistory = Optional.of(chatHistory); return this; } @java.lang.Override @JsonSetter(value = "chat_history", nulls = Nulls.SKIP) public _FinalStage chatHistory(Optional> chatHistory) { this.chatHistory = chatHistory; return this; } /** *

When specified, the default Cohere preamble will be replaced with the provided one. Preambles are a part of the prompt used to adjust the model's overall behavior and conversation style, and use the SYSTEM role.

*

The SYSTEM role is also used for the contents of the optional chat_history= parameter. When used with the chat_history= parameter it adds content throughout a conversation. Conversely, when used with the preamble= parameter it adds content at the start of the conversation only. * Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage preamble(String preamble) { this.preamble = Optional.of(preamble); return this; } @java.lang.Override @JsonSetter(value = "preamble", nulls = Nulls.SKIP) public _FinalStage preamble(Optional preamble) { this.preamble = preamble; return this; } /** *

Defaults to command-r-plus.

*

The name of a compatible Cohere model or the ID of a fine-tuned model. * Compatible Deployments: Cohere Platform, Private Deployments

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage model(String model) { this.model = Optional.of(model); return this; } @java.lang.Override @JsonSetter(value = "model", nulls = Nulls.SKIP) public _FinalStage model(Optional model) { this.model = model; return this; } @java.lang.Override public ChatRequest build() { return new ChatRequest( message, model, preamble, chatHistory, conversationId, promptTruncation, connectors, searchQueriesOnly, documents, citationQuality, temperature, maxTokens, maxInputTokens, k, p, seed, stopSequences, frequencyPenalty, presencePenalty, rawPrompting, returnPrompt, tools, toolResults, additionalProperties); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy