From 1cccf8c6d85eecc05866eee35ef20991a51d5a8f Mon Sep 17 00:00:00 2001 From: "fern-api[bot]" <115122769+fern-api[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 05:52:44 -0500 Subject: [PATCH] SDK regeneration (#32) Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> --- build.gradle | 2 +- src/main/java/com/cohere/api/Cohere.java | 213 ++++- .../com/cohere/api/core/ClientOptions.java | 2 +- .../com/cohere/api/requests/ChatRequest.java | 41 +- .../api/requests/ChatStreamRequest.java | 41 +- .../com/cohere/api/requests/EmbedRequest.java | 47 +- .../finetuning/finetuning/types/Settings.java | 4 +- .../com/cohere/api/resources/v2/V2Client.java | 313 ++++++++ .../resources/v2/requests/V2ChatRequest.java | 729 ++++++++++++++++++ .../v2/requests/V2ChatStreamRequest.java | 729 ++++++++++++++++++ .../resources/v2/types/AssistantMessage.java | 170 ++++ .../v2/types/AssistantMessageContent.java | 97 +++ .../v2/types/AssistantMessageContentItem.java | 145 ++++ .../v2/types/AssistantMessageResponse.java | 175 +++++ .../AssistantMessageResponseContentItem.java | 145 ++++ .../v2/types/ChatContentDeltaEvent.java | 120 +++ .../v2/types/ChatContentDeltaEventDelta.java | 96 +++ .../ChatContentDeltaEventDeltaMessage.java | 96 +++ ...tContentDeltaEventDeltaMessageContent.java | 96 +++ .../v2/types/ChatContentEndEvent.java | 95 +++ .../v2/types/ChatContentStartEvent.java | 120 +++ .../v2/types/ChatContentStartEventDelta.java | 96 +++ .../ChatContentStartEventDeltaMessage.java | 96 +++ ...tContentStartEventDeltaMessageContent.java | 119 +++ .../resources/v2/types/ChatFinishReason.java | 34 + .../api/resources/v2/types/ChatMessage2.java | 315 ++++++++ .../v2/types/ChatMessageEndEvent.java | 118 +++ .../v2/types/ChatMessageEndEventDelta.java | 118 +++ .../v2/types/ChatMessageStartEvent.java | 121 +++ .../v2/types/ChatMessageStartEventDelta.java | 96 +++ .../ChatMessageStartEventDeltaMessage.java | 98 +++ .../v2/types/ChatStreamEventType.java | 59 ++ .../v2/types/ChatToolCallDeltaEvent.java | 120 +++ .../v2/types/ChatToolCallDeltaEventDelta.java | 96 +++ .../ChatToolCallDeltaEventDeltaToolCall.java | 97 +++ ...olCallDeltaEventDeltaToolCallFunction.java | 97 +++ .../v2/types/ChatToolCallEndEvent.java | 95 +++ .../v2/types/ChatToolCallStartEvent.java | 120 +++ .../v2/types/ChatToolCallStartEventDelta.java | 96 +++ .../ChatToolCallStartEventDeltaToolCall.java | 144 ++++ ...olCallStartEventDeltaToolCallFunction.java | 119 +++ .../v2/types/ChatToolPlanDeltaEvent.java | 96 +++ .../v2/types/ChatToolPlanDeltaEventDelta.java | 95 +++ .../api/resources/v2/types/Citation.java | 170 ++++ .../resources/v2/types/CitationEndEvent.java | 95 +++ .../resources/v2/types/CitationOptions.java | 99 +++ .../v2/types/CitationOptionsMode.java | 26 + .../v2/types/CitationStartEvent.java | 120 +++ .../v2/types/CitationStartEventDelta.java | 96 +++ .../types/CitationStartEventDeltaMessage.java | 95 +++ .../api/resources/v2/types/Content.java | 145 ++++ .../api/resources/v2/types/Document.java | 130 ++++ .../resources/v2/types/DocumentContent.java | 101 +++ .../resources/v2/types/DocumentSource.java | 121 +++ .../v2/types/IChatStreamEventType.java | 6 + .../cohere/api/resources/v2/types/Images.java | 239 ++++++ .../v2/types/JsonResponseFormat2.java | 109 +++ .../v2/types/NonStreamedChatResponse2.java | 233 ++++++ .../resources/v2/types/ResponseFormat2.java | 200 +++++ .../cohere/api/resources/v2/types/Source.java | 200 +++++ .../v2/types/StreamedChatResponse2.java | 707 +++++++++++++++++ .../api/resources/v2/types/SystemMessage.java | 101 +++ .../v2/types/SystemMessageContent.java | 97 +++ .../v2/types/SystemMessageContentItem.java | 145 ++++ .../api/resources/v2/types/TextContent.java | 101 +++ .../v2/types/TextResponseFormat2.java | 59 ++ .../cohere/api/resources/v2/types/Texts.java | 307 ++++++++ .../api/resources/v2/types/TextsTruncate.java | 26 + .../cohere/api/resources/v2/types/Tool2.java | 120 +++ .../api/resources/v2/types/Tool2Function.java | 152 ++++ .../api/resources/v2/types/ToolCall2.java | 143 ++++ .../resources/v2/types/ToolCall2Function.java | 118 +++ .../api/resources/v2/types/ToolContent.java | 200 +++++ .../api/resources/v2/types/ToolMessage2.java | 138 ++++ .../v2/types/ToolMessage2ToolContent.java | 96 +++ .../api/resources/v2/types/ToolSource.java | 121 +++ .../cohere/api/resources/v2/types/Usage.java | 120 +++ .../resources/v2/types/UsageBilledUnits.java | 181 +++++ .../api/resources/v2/types/UsageTokens.java | 124 +++ .../api/resources/v2/types/UserMessage.java | 110 +++ .../v2/types/UserMessageContent.java | 96 +++ .../v2/types/V2ChatRequestDocumentsItem.java | 94 +++ .../v2/types/V2ChatRequestSafetyMode.java | 26 + .../V2ChatStreamRequestDocumentsItem.java | 95 +++ .../types/V2ChatStreamRequestSafetyMode.java | 26 + .../resources/v2/types/V2EmbedRequest.java | 375 +++++++++ .../com/cohere/api/types/EmbedInputType.java | 4 +- 87 files changed, 11952 insertions(+), 36 deletions(-) create mode 100644 src/main/java/com/cohere/api/resources/v2/V2Client.java create mode 100644 src/main/java/com/cohere/api/resources/v2/requests/V2ChatRequest.java create mode 100644 src/main/java/com/cohere/api/resources/v2/requests/V2ChatStreamRequest.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/AssistantMessage.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/AssistantMessageContent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/AssistantMessageContentItem.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/AssistantMessageResponse.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/AssistantMessageResponseContentItem.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDelta.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDeltaMessage.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDeltaMessageContent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatContentEndEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDelta.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDeltaMessage.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDeltaMessageContent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatFinishReason.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatMessage2.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatMessageEndEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatMessageEndEventDelta.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEventDelta.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEventDeltaMessage.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatStreamEventType.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDelta.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDeltaToolCall.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDeltaToolCallFunction.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolCallEndEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDelta.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDeltaToolCall.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDeltaToolCallFunction.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolPlanDeltaEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ChatToolPlanDeltaEventDelta.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/Citation.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/CitationEndEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/CitationOptions.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/CitationOptionsMode.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/CitationStartEvent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/CitationStartEventDelta.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/CitationStartEventDeltaMessage.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/Content.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/Document.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/DocumentContent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/DocumentSource.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/IChatStreamEventType.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/Images.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/JsonResponseFormat2.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/NonStreamedChatResponse2.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ResponseFormat2.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/Source.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/StreamedChatResponse2.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/SystemMessage.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/SystemMessageContent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/SystemMessageContentItem.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/TextContent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/TextResponseFormat2.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/Texts.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/TextsTruncate.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/Tool2.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/Tool2Function.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ToolCall2.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ToolCall2Function.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ToolContent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ToolMessage2.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ToolMessage2ToolContent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/ToolSource.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/Usage.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/UsageBilledUnits.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/UsageTokens.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/UserMessage.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/UserMessageContent.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/V2ChatRequestDocumentsItem.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/V2ChatRequestSafetyMode.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/V2ChatStreamRequestDocumentsItem.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/V2ChatStreamRequestSafetyMode.java create mode 100644 src/main/java/com/cohere/api/resources/v2/types/V2EmbedRequest.java diff --git a/build.gradle b/build.gradle index 301d49e..683a171 100644 --- a/build.gradle +++ b/build.gradle @@ -50,7 +50,7 @@ publishing { maven(MavenPublication) { groupId = 'com.cohere' artifactId = 'cohere-java' - version = '1.3.1' + version = '1.3.2' from components.java pom { name = 'cohere' diff --git a/src/main/java/com/cohere/api/Cohere.java b/src/main/java/com/cohere/api/Cohere.java index 362a79c..03d4488 100644 --- a/src/main/java/com/cohere/api/Cohere.java +++ b/src/main/java/com/cohere/api/Cohere.java @@ -37,6 +37,7 @@ import com.cohere.api.resources.embedjobs.EmbedJobsClient; import com.cohere.api.resources.finetuning.FinetuningClient; import com.cohere.api.resources.models.ModelsClient; +import com.cohere.api.resources.v2.V2Client; import com.cohere.api.types.CheckApiKeyResponse; import com.cohere.api.types.ClassifyResponse; import com.cohere.api.types.ClientClosedRequestErrorBody; @@ -55,6 +56,8 @@ import com.cohere.api.types.UnprocessableEntityErrorBody; import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import java.util.function.Supplier; import okhttp3.Headers; import okhttp3.HttpUrl; @@ -67,6 +70,8 @@ public class Cohere { protected final ClientOptions clientOptions; + protected final Supplier v2Client; + protected final Supplier embedJobsClient; protected final Supplier datasetsClient; @@ -79,6 +84,7 @@ public class Cohere { public Cohere(ClientOptions clientOptions) { this.clientOptions = clientOptions; + this.v2Client = Suppliers.memoize(() -> new V2Client(clientOptions)); this.embedJobsClient = Suppliers.memoize(() -> new EmbedJobsClient(clientOptions)); this.datasetsClient = Suppliers.memoize(() -> new DatasetsClient(clientOptions)); this.connectorsClient = Suppliers.memoize(() -> new ConnectorsClient(clientOptions)); @@ -88,7 +94,7 @@ public Cohere(ClientOptions clientOptions) { /** * Generates a text response to a user message. - * To learn how to use the Chat API with Streaming and RAG follow our Text Generation guides. + * To learn how to use the Chat API and RAG follow our Text Generation guides. */ public Iterable chatStream(ChatStreamRequest request) { return chatStream(request, null); @@ -96,26 +102,107 @@ public Iterable chatStream(ChatStreamRequest request) { /** * Generates a text response to a user message. - * To learn how to use the Chat API with Streaming and RAG follow our Text Generation guides. + * To learn how to use the Chat API and RAG follow our Text Generation guides. */ public Iterable chatStream(ChatStreamRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/chat") .build(); + Map properties = new HashMap<>(); + properties.put("message", request.getMessage()); + if (request.getModel().isPresent()) { + properties.put("model", request.getModel()); + } + properties.put("stream", request.getStream()); + if (request.getPreamble().isPresent()) { + properties.put("preamble", request.getPreamble()); + } + if (request.getChatHistory().isPresent()) { + properties.put("chat_history", request.getChatHistory()); + } + if (request.getConversationId().isPresent()) { + properties.put("conversation_id", request.getConversationId()); + } + if (request.getPromptTruncation().isPresent()) { + properties.put("prompt_truncation", request.getPromptTruncation()); + } + if (request.getConnectors().isPresent()) { + properties.put("connectors", request.getConnectors()); + } + if (request.getSearchQueriesOnly().isPresent()) { + properties.put("search_queries_only", request.getSearchQueriesOnly()); + } + if (request.getDocuments().isPresent()) { + properties.put("documents", request.getDocuments()); + } + if (request.getCitationQuality().isPresent()) { + properties.put("citation_quality", request.getCitationQuality()); + } + if (request.getTemperature().isPresent()) { + properties.put("temperature", request.getTemperature()); + } + if (request.getMaxTokens().isPresent()) { + properties.put("max_tokens", request.getMaxTokens()); + } + if (request.getMaxInputTokens().isPresent()) { + properties.put("max_input_tokens", request.getMaxInputTokens()); + } + if (request.getK().isPresent()) { + properties.put("k", request.getK()); + } + if (request.getP().isPresent()) { + properties.put("p", request.getP()); + } + if (request.getSeed().isPresent()) { + properties.put("seed", request.getSeed()); + } + if (request.getStopSequences().isPresent()) { + properties.put("stop_sequences", request.getStopSequences()); + } + if (request.getFrequencyPenalty().isPresent()) { + properties.put("frequency_penalty", request.getFrequencyPenalty()); + } + if (request.getPresencePenalty().isPresent()) { + properties.put("presence_penalty", request.getPresencePenalty()); + } + if (request.getRawPrompting().isPresent()) { + properties.put("raw_prompting", request.getRawPrompting()); + } + if (request.getReturnPrompt().isPresent()) { + properties.put("return_prompt", request.getReturnPrompt()); + } + if (request.getTools().isPresent()) { + properties.put("tools", request.getTools()); + } + if (request.getToolResults().isPresent()) { + properties.put("tool_results", request.getToolResults()); + } + if (request.getForceSingleStep().isPresent()) { + properties.put("force_single_step", request.getForceSingleStep()); + } + if (request.getResponseFormat().isPresent()) { + properties.put("response_format", request.getResponseFormat()); + } + if (request.getSafetyMode().isPresent()) { + properties.put("safety_mode", request.getSafetyMode()); + } RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new CohereApiError("Failed to serialize request", e); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(properties), MediaTypes.APPLICATION_JSON); + } catch (Exception e) { + throw new RuntimeException(e); } - Request okhttpRequest = new Request.Builder() + Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .build(); + .addHeader("Content-Type", "application/json"); + if (request.getAccepts().isPresent()) { + _requestBuilder.addHeader("Accepts", request.getAccepts().get()); + } + Request okhttpRequest = _requestBuilder.build(); OkHttpClient client = clientOptions.httpClient(); if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); @@ -176,7 +263,7 @@ public Iterable chatStream(ChatStreamRequest request, Requ /** * Generates a text response to a user message. - * To learn how to use the Chat API with Streaming and RAG follow our Text Generation guides. + * To learn how to use the Chat API and RAG follow our Text Generation guides. */ public NonStreamedChatResponse chat(ChatRequest request) { return chat(request, null); @@ -184,26 +271,107 @@ public NonStreamedChatResponse chat(ChatRequest request) { /** * Generates a text response to a user message. - * To learn how to use the Chat API with Streaming and RAG follow our Text Generation guides. + * To learn how to use the Chat API and RAG follow our Text Generation guides. */ public NonStreamedChatResponse chat(ChatRequest request, RequestOptions requestOptions) { HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) .newBuilder() .addPathSegments("v1/chat") .build(); + Map properties = new HashMap<>(); + properties.put("message", request.getMessage()); + if (request.getModel().isPresent()) { + properties.put("model", request.getModel()); + } + properties.put("stream", request.getStream()); + if (request.getPreamble().isPresent()) { + properties.put("preamble", request.getPreamble()); + } + if (request.getChatHistory().isPresent()) { + properties.put("chat_history", request.getChatHistory()); + } + if (request.getConversationId().isPresent()) { + properties.put("conversation_id", request.getConversationId()); + } + if (request.getPromptTruncation().isPresent()) { + properties.put("prompt_truncation", request.getPromptTruncation()); + } + if (request.getConnectors().isPresent()) { + properties.put("connectors", request.getConnectors()); + } + if (request.getSearchQueriesOnly().isPresent()) { + properties.put("search_queries_only", request.getSearchQueriesOnly()); + } + if (request.getDocuments().isPresent()) { + properties.put("documents", request.getDocuments()); + } + if (request.getCitationQuality().isPresent()) { + properties.put("citation_quality", request.getCitationQuality()); + } + if (request.getTemperature().isPresent()) { + properties.put("temperature", request.getTemperature()); + } + if (request.getMaxTokens().isPresent()) { + properties.put("max_tokens", request.getMaxTokens()); + } + if (request.getMaxInputTokens().isPresent()) { + properties.put("max_input_tokens", request.getMaxInputTokens()); + } + if (request.getK().isPresent()) { + properties.put("k", request.getK()); + } + if (request.getP().isPresent()) { + properties.put("p", request.getP()); + } + if (request.getSeed().isPresent()) { + properties.put("seed", request.getSeed()); + } + if (request.getStopSequences().isPresent()) { + properties.put("stop_sequences", request.getStopSequences()); + } + if (request.getFrequencyPenalty().isPresent()) { + properties.put("frequency_penalty", request.getFrequencyPenalty()); + } + if (request.getPresencePenalty().isPresent()) { + properties.put("presence_penalty", request.getPresencePenalty()); + } + if (request.getRawPrompting().isPresent()) { + properties.put("raw_prompting", request.getRawPrompting()); + } + if (request.getReturnPrompt().isPresent()) { + properties.put("return_prompt", request.getReturnPrompt()); + } + if (request.getTools().isPresent()) { + properties.put("tools", request.getTools()); + } + if (request.getToolResults().isPresent()) { + properties.put("tool_results", request.getToolResults()); + } + if (request.getForceSingleStep().isPresent()) { + properties.put("force_single_step", request.getForceSingleStep()); + } + if (request.getResponseFormat().isPresent()) { + properties.put("response_format", request.getResponseFormat()); + } + if (request.getSafetyMode().isPresent()) { + properties.put("safety_mode", request.getSafetyMode()); + } RequestBody body; try { body = RequestBody.create( - ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); - } catch (JsonProcessingException e) { - throw new CohereApiError("Failed to serialize request", e); + ObjectMappers.JSON_MAPPER.writeValueAsBytes(properties), MediaTypes.APPLICATION_JSON); + } catch (Exception e) { + throw new RuntimeException(e); } - Request okhttpRequest = new Request.Builder() + Request.Builder _requestBuilder = new Request.Builder() .url(httpUrl) .method("POST", body) .headers(Headers.of(clientOptions.headers(requestOptions))) - .addHeader("Content-Type", "application/json") - .build(); + .addHeader("Content-Type", "application/json"); + if (request.getAccepts().isPresent()) { + _requestBuilder.addHeader("Accepts", request.getAccepts().get()); + } + Request okhttpRequest = _requestBuilder.build(); OkHttpClient client = clientOptions.httpClient(); if (requestOptions != null && requestOptions.getTimeout().isPresent()) { client = clientOptions.httpClientWithTimeout(requestOptions); @@ -448,6 +616,15 @@ public Generation generate(GenerateRequest request, RequestOptions requestOption } } + /** + * This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents. + *

Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.

+ *

If you want to learn more how to use the embedding model, have a look at the Semantic Search Guide.

+ */ + public EmbedResponse embed() { + return embed(EmbedRequest.builder().build()); + } + /** * This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents. *

Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.

@@ -1055,6 +1232,10 @@ public CheckApiKeyResponse checkApiKey(RequestOptions requestOptions) { } } + public V2Client v2() { + return this.v2Client.get(); + } + public EmbedJobsClient embedJobs() { return this.embedJobsClient.get(); } diff --git a/src/main/java/com/cohere/api/core/ClientOptions.java b/src/main/java/com/cohere/api/core/ClientOptions.java index f51ecd7..943764d 100644 --- a/src/main/java/com/cohere/api/core/ClientOptions.java +++ b/src/main/java/com/cohere/api/core/ClientOptions.java @@ -30,7 +30,7 @@ private ClientOptions( { put("X-Fern-Language", "JAVA"); put("X-Fern-SDK-Name", "com.cohere.fern:api-sdk"); - put("X-Fern-SDK-Version", "1.3.1"); + put("X-Fern-SDK-Version", "1.3.2"); } }); this.headerSuppliers = headerSuppliers; diff --git a/src/main/java/com/cohere/api/requests/ChatRequest.java b/src/main/java/com/cohere/api/requests/ChatRequest.java index ccae20d..09b1ec5 100644 --- a/src/main/java/com/cohere/api/requests/ChatRequest.java +++ b/src/main/java/com/cohere/api/requests/ChatRequest.java @@ -29,6 +29,8 @@ @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonDeserialize(builder = ChatRequest.Builder.class) public final class ChatRequest { + private final Optional accepts; + private final String message; private final Optional model; @@ -84,6 +86,7 @@ public final class ChatRequest { private final Map additionalProperties; private ChatRequest( + Optional accepts, String message, Optional model, Optional preamble, @@ -111,6 +114,7 @@ private ChatRequest( Optional responseFormat, Optional safetyMode, Map additionalProperties) { + this.accepts = accepts; this.message = message; this.model = model; this.preamble = preamble; @@ -140,6 +144,14 @@ private ChatRequest( this.additionalProperties = additionalProperties; } + /** + * @return Pass text/event-stream to receive the streamed response as server-sent events. The default is \n delimited events. + */ + @JsonProperty("Accepts") + public Optional getAccepts() { + return accepts; + } + /** * @return Text input for the model to respond to. *

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

@@ -451,7 +463,8 @@ public Map getAdditionalProperties() { } private boolean equalTo(ChatRequest other) { - return message.equals(other.message) + return accepts.equals(other.accepts) + && message.equals(other.message) && model.equals(other.model) && preamble.equals(other.preamble) && chatHistory.equals(other.chatHistory) @@ -482,6 +495,7 @@ private boolean equalTo(ChatRequest other) { @java.lang.Override public int hashCode() { return Objects.hash( + this.accepts, this.message, this.model, this.preamble, @@ -528,6 +542,10 @@ public interface MessageStage { public interface _FinalStage { ChatRequest build(); + _FinalStage accepts(Optional accepts); + + _FinalStage accepts(String accepts); + _FinalStage model(Optional model); _FinalStage model(String model); @@ -683,6 +701,8 @@ public static final class Builder implements MessageStage, _FinalStage { private Optional model = Optional.empty(); + private Optional accepts = Optional.empty(); + @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -690,6 +710,7 @@ private Builder() {} @java.lang.Override public Builder from(ChatRequest other) { + accepts(other.getAccepts()); message(other.getMessage()); model(other.getModel()); preamble(other.getPreamble()); @@ -1234,9 +1255,27 @@ public _FinalStage model(Optional model) { return this; } + /** + *

Pass text/event-stream to receive the streamed response as server-sent events. The default is \n delimited events.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage accepts(String accepts) { + this.accepts = Optional.of(accepts); + return this; + } + + @java.lang.Override + @JsonSetter(value = "Accepts", nulls = Nulls.SKIP) + public _FinalStage accepts(Optional accepts) { + this.accepts = accepts; + return this; + } + @java.lang.Override public ChatRequest build() { return new ChatRequest( + accepts, message, model, preamble, diff --git a/src/main/java/com/cohere/api/requests/ChatStreamRequest.java b/src/main/java/com/cohere/api/requests/ChatStreamRequest.java index c1d1eb3..54ae350 100644 --- a/src/main/java/com/cohere/api/requests/ChatStreamRequest.java +++ b/src/main/java/com/cohere/api/requests/ChatStreamRequest.java @@ -29,6 +29,8 @@ @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonDeserialize(builder = ChatStreamRequest.Builder.class) public final class ChatStreamRequest { + private final Optional accepts; + private final String message; private final Optional model; @@ -84,6 +86,7 @@ public final class ChatStreamRequest { private final Map additionalProperties; private ChatStreamRequest( + Optional accepts, String message, Optional model, Optional preamble, @@ -111,6 +114,7 @@ private ChatStreamRequest( Optional responseFormat, Optional safetyMode, Map additionalProperties) { + this.accepts = accepts; this.message = message; this.model = model; this.preamble = preamble; @@ -140,6 +144,14 @@ private ChatStreamRequest( this.additionalProperties = additionalProperties; } + /** + * @return Pass text/event-stream to receive the streamed response as server-sent events. The default is \n delimited events. + */ + @JsonProperty("Accepts") + public Optional getAccepts() { + return accepts; + } + /** * @return Text input for the model to respond to. *

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

@@ -451,7 +463,8 @@ public Map getAdditionalProperties() { } private boolean equalTo(ChatStreamRequest other) { - return message.equals(other.message) + return accepts.equals(other.accepts) + && message.equals(other.message) && model.equals(other.model) && preamble.equals(other.preamble) && chatHistory.equals(other.chatHistory) @@ -482,6 +495,7 @@ private boolean equalTo(ChatStreamRequest other) { @java.lang.Override public int hashCode() { return Objects.hash( + this.accepts, this.message, this.model, this.preamble, @@ -528,6 +542,10 @@ public interface MessageStage { public interface _FinalStage { ChatStreamRequest build(); + _FinalStage accepts(Optional accepts); + + _FinalStage accepts(String accepts); + _FinalStage model(Optional model); _FinalStage model(String model); @@ -683,6 +701,8 @@ public static final class Builder implements MessageStage, _FinalStage { private Optional model = Optional.empty(); + private Optional accepts = Optional.empty(); + @JsonAnySetter private Map additionalProperties = new HashMap<>(); @@ -690,6 +710,7 @@ private Builder() {} @java.lang.Override public Builder from(ChatStreamRequest other) { + accepts(other.getAccepts()); message(other.getMessage()); model(other.getModel()); preamble(other.getPreamble()); @@ -1234,9 +1255,27 @@ public _FinalStage model(Optional model) { return this; } + /** + *

Pass text/event-stream to receive the streamed response as server-sent events. The default is \n delimited events.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage accepts(String accepts) { + this.accepts = Optional.of(accepts); + return this; + } + + @java.lang.Override + @JsonSetter(value = "Accepts", nulls = Nulls.SKIP) + public _FinalStage accepts(Optional accepts) { + this.accepts = accepts; + return this; + } + @java.lang.Override public ChatStreamRequest build() { return new ChatStreamRequest( + accepts, message, model, preamble, diff --git a/src/main/java/com/cohere/api/requests/EmbedRequest.java b/src/main/java/com/cohere/api/requests/EmbedRequest.java index 3a90448..c01ffd7 100644 --- a/src/main/java/com/cohere/api/requests/EmbedRequest.java +++ b/src/main/java/com/cohere/api/requests/EmbedRequest.java @@ -15,7 +15,6 @@ 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; @@ -25,7 +24,9 @@ @JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonDeserialize(builder = EmbedRequest.Builder.class) public final class EmbedRequest { - private final List texts; + private final Optional> texts; + + private final Optional> images; private final Optional model; @@ -38,13 +39,15 @@ public final class EmbedRequest { private final Map additionalProperties; private EmbedRequest( - List texts, + Optional> texts, + Optional> images, Optional model, Optional inputType, Optional> embeddingTypes, Optional truncate, Map additionalProperties) { this.texts = texts; + this.images = images; this.model = model; this.inputType = inputType; this.embeddingTypes = embeddingTypes; @@ -56,10 +59,19 @@ private EmbedRequest( * @return An array of strings for the model to embed. Maximum number of texts per call is 96. We recommend reducing the length of each text to be under 512 tokens for optimal quality. */ @JsonProperty("texts") - public List getTexts() { + public Optional> getTexts() { return texts; } + /** + * @return An array of image data URIs for the model to embed. Maximum number of images per call is 1. + *

The image must be a valid data URI. The image must be in either image/jpeg or image/png format and has a maximum size of 5MB.

+ */ + @JsonProperty("images") + public Optional> getImages() { + return images; + } + /** * @return Defaults to embed-english-v2.0 *

The identifier of the model. Smaller "light" models are faster, while larger models will perform better. Custom models can also be supplied with their full ID.

@@ -136,6 +148,7 @@ public Map getAdditionalProperties() { private boolean equalTo(EmbedRequest other) { return texts.equals(other.texts) + && images.equals(other.images) && model.equals(other.model) && inputType.equals(other.inputType) && embeddingTypes.equals(other.embeddingTypes) @@ -144,7 +157,7 @@ private boolean equalTo(EmbedRequest other) { @java.lang.Override public int hashCode() { - return Objects.hash(this.texts, this.model, this.inputType, this.embeddingTypes, this.truncate); + return Objects.hash(this.texts, this.images, this.model, this.inputType, this.embeddingTypes, this.truncate); } @java.lang.Override @@ -158,7 +171,9 @@ public static Builder builder() { @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder { - private List texts = new ArrayList<>(); + private Optional> texts = Optional.empty(); + + private Optional> images = Optional.empty(); private Optional model = Optional.empty(); @@ -175,6 +190,7 @@ private Builder() {} public Builder from(EmbedRequest other) { texts(other.getTexts()); + images(other.getImages()); model(other.getModel()); inputType(other.getInputType()); embeddingTypes(other.getEmbeddingTypes()); @@ -183,19 +199,24 @@ public Builder from(EmbedRequest other) { } @JsonSetter(value = "texts", nulls = Nulls.SKIP) + public Builder texts(Optional> texts) { + this.texts = texts; + return this; + } + public Builder texts(List texts) { - this.texts.clear(); - this.texts.addAll(texts); + this.texts = Optional.of(texts); return this; } - public Builder addTexts(String texts) { - this.texts.add(texts); + @JsonSetter(value = "images", nulls = Nulls.SKIP) + public Builder images(Optional> images) { + this.images = images; return this; } - public Builder addAllTexts(List texts) { - this.texts.addAll(texts); + public Builder images(List images) { + this.images = Optional.of(images); return this; } @@ -244,7 +265,7 @@ public Builder truncate(EmbedRequestTruncate truncate) { } public EmbedRequest build() { - return new EmbedRequest(texts, model, inputType, embeddingTypes, truncate, additionalProperties); + return new EmbedRequest(texts, images, model, inputType, embeddingTypes, truncate, additionalProperties); } } } diff --git a/src/main/java/com/cohere/api/resources/finetuning/finetuning/types/Settings.java b/src/main/java/com/cohere/api/resources/finetuning/finetuning/types/Settings.java index a63112a..c751d56 100644 --- a/src/main/java/com/cohere/api/resources/finetuning/finetuning/types/Settings.java +++ b/src/main/java/com/cohere/api/resources/finetuning/finetuning/types/Settings.java @@ -80,7 +80,7 @@ public Optional getMultiLabel() { } /** - * @return The Weights & Biases configuration. + * @return The Weights & Biases configuration (Chat fine-tuning only). */ @JsonProperty("wandb") public Optional getWandb() { @@ -196,7 +196,7 @@ public _FinalStage datasetId(String datasetId) { } /** - *

The Weights & Biases configuration.

+ *

The Weights & Biases configuration (Chat fine-tuning only).

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override diff --git a/src/main/java/com/cohere/api/resources/v2/V2Client.java b/src/main/java/com/cohere/api/resources/v2/V2Client.java new file mode 100644 index 0000000..fa73ba8 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/V2Client.java @@ -0,0 +1,313 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2; + +import com.cohere.api.core.ClientOptions; +import com.cohere.api.core.CohereApiApiError; +import com.cohere.api.core.CohereApiError; +import com.cohere.api.core.MediaTypes; +import com.cohere.api.core.ObjectMappers; +import com.cohere.api.core.RequestOptions; +import com.cohere.api.core.Stream; +import com.cohere.api.errors.CohereApiBadRequestError; +import com.cohere.api.errors.CohereApiClientClosedRequestError; +import com.cohere.api.errors.CohereApiForbiddenError; +import com.cohere.api.errors.CohereApiGatewayTimeoutError; +import com.cohere.api.errors.CohereApiInternalServerError; +import com.cohere.api.errors.CohereApiNotFoundError; +import com.cohere.api.errors.CohereApiNotImplementedError; +import com.cohere.api.errors.CohereApiServiceUnavailableError; +import com.cohere.api.errors.CohereApiTooManyRequestsError; +import com.cohere.api.errors.CohereApiUnauthorizedError; +import com.cohere.api.errors.CohereApiUnprocessableEntityError; +import com.cohere.api.resources.v2.requests.V2ChatRequest; +import com.cohere.api.resources.v2.requests.V2ChatStreamRequest; +import com.cohere.api.resources.v2.types.NonStreamedChatResponse2; +import com.cohere.api.resources.v2.types.StreamedChatResponse2; +import com.cohere.api.resources.v2.types.V2EmbedRequest; +import com.cohere.api.types.ClientClosedRequestErrorBody; +import com.cohere.api.types.EmbedByTypeResponse; +import com.cohere.api.types.GatewayTimeoutErrorBody; +import com.cohere.api.types.NotImplementedErrorBody; +import com.cohere.api.types.TooManyRequestsErrorBody; +import com.cohere.api.types.UnprocessableEntityErrorBody; +import com.fasterxml.jackson.core.JsonProcessingException; +import java.io.IOException; +import okhttp3.Headers; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import okhttp3.ResponseBody; + +public class V2Client { + protected final ClientOptions clientOptions; + + public V2Client(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + } + + /** + * Generates a message from the model in response to a provided conversation. To learn how to use the Chat API with Streaming and RAG follow our Text Generation guides. + */ + public Iterable chatStream(V2ChatStreamRequest request) { + return chatStream(request, null); + } + + /** + * Generates a message from the model in response to a provided conversation. To learn how to use the Chat API with Streaming and RAG follow our Text Generation guides. + */ + public Iterable chatStream(V2ChatStreamRequest request, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/chat") + .build(); + RequestBody body; + try { + body = RequestBody.create( + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + } catch (JsonProcessingException e) { + throw new CohereApiError("Failed to serialize request", e); + } + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("POST", body) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Content-Type", "application/json") + .build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try (Response response = client.newCall(okhttpRequest).execute()) { + ResponseBody responseBody = response.body(); + if (response.isSuccessful()) { + return new Stream(StreamedChatResponse2.class, responseBody.charStream(), "\n"); + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + throw new CohereApiBadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 401: + throw new CohereApiUnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 403: + throw new CohereApiForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 404: + throw new CohereApiNotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 422: + throw new CohereApiUnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, UnprocessableEntityErrorBody.class)); + case 429: + throw new CohereApiTooManyRequestsError(ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, TooManyRequestsErrorBody.class)); + case 499: + throw new CohereApiClientClosedRequestError(ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, ClientClosedRequestErrorBody.class)); + case 500: + throw new CohereApiInternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 501: + throw new CohereApiNotImplementedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, NotImplementedErrorBody.class)); + case 503: + throw new CohereApiServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 504: + throw new CohereApiGatewayTimeoutError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GatewayTimeoutErrorBody.class)); + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + throw new CohereApiApiError( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + } catch (IOException e) { + throw new CohereApiError("Network error executing HTTP request", e); + } + } + + /** + * Generates a message from the model in response to a provided conversation. To learn how to use the Chat API with Streaming and RAG follow our Text Generation guides. + */ + public NonStreamedChatResponse2 chat(V2ChatRequest request) { + return chat(request, null); + } + + /** + * Generates a message from the model in response to a provided conversation. To learn how to use the Chat API with Streaming and RAG follow our Text Generation guides. + */ + public NonStreamedChatResponse2 chat(V2ChatRequest request, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/chat") + .build(); + RequestBody body; + try { + body = RequestBody.create( + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + } catch (JsonProcessingException e) { + throw new CohereApiError("Failed to serialize request", e); + } + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("POST", body) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Content-Type", "application/json") + .build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try (Response response = client.newCall(okhttpRequest).execute()) { + ResponseBody responseBody = response.body(); + if (response.isSuccessful()) { + return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), NonStreamedChatResponse2.class); + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + throw new CohereApiBadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 401: + throw new CohereApiUnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 403: + throw new CohereApiForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 404: + throw new CohereApiNotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 422: + throw new CohereApiUnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, UnprocessableEntityErrorBody.class)); + case 429: + throw new CohereApiTooManyRequestsError(ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, TooManyRequestsErrorBody.class)); + case 499: + throw new CohereApiClientClosedRequestError(ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, ClientClosedRequestErrorBody.class)); + case 500: + throw new CohereApiInternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 501: + throw new CohereApiNotImplementedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, NotImplementedErrorBody.class)); + case 503: + throw new CohereApiServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 504: + throw new CohereApiGatewayTimeoutError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GatewayTimeoutErrorBody.class)); + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + throw new CohereApiApiError( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + } catch (IOException e) { + throw new CohereApiError("Network error executing HTTP request", e); + } + } + + /** + * This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents. + *

Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.

+ *

If you want to learn more how to use the embedding model, have a look at the Semantic Search Guide.

+ */ + public EmbedByTypeResponse embed(V2EmbedRequest request) { + return embed(request, null); + } + + /** + * This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents. + *

Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.

+ *

If you want to learn more how to use the embedding model, have a look at the Semantic Search Guide.

+ */ + public EmbedByTypeResponse embed(V2EmbedRequest request, RequestOptions requestOptions) { + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) + .newBuilder() + .addPathSegments("v2/embed") + .build(); + RequestBody body; + try { + body = RequestBody.create( + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); + } catch (JsonProcessingException e) { + throw new CohereApiError("Failed to serialize request", e); + } + Request okhttpRequest = new Request.Builder() + .url(httpUrl) + .method("POST", body) + .headers(Headers.of(clientOptions.headers(requestOptions))) + .addHeader("Content-Type", "application/json") + .build(); + OkHttpClient client = clientOptions.httpClient(); + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { + client = clientOptions.httpClientWithTimeout(requestOptions); + } + try (Response response = client.newCall(okhttpRequest).execute()) { + ResponseBody responseBody = response.body(); + if (response.isSuccessful()) { + return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), EmbedByTypeResponse.class); + } + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; + try { + switch (response.code()) { + case 400: + throw new CohereApiBadRequestError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 401: + throw new CohereApiUnauthorizedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 403: + throw new CohereApiForbiddenError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 404: + throw new CohereApiNotFoundError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 422: + throw new CohereApiUnprocessableEntityError(ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, UnprocessableEntityErrorBody.class)); + case 429: + throw new CohereApiTooManyRequestsError(ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, TooManyRequestsErrorBody.class)); + case 499: + throw new CohereApiClientClosedRequestError(ObjectMappers.JSON_MAPPER.readValue( + responseBodyString, ClientClosedRequestErrorBody.class)); + case 500: + throw new CohereApiInternalServerError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 501: + throw new CohereApiNotImplementedError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, NotImplementedErrorBody.class)); + case 503: + throw new CohereApiServiceUnavailableError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + case 504: + throw new CohereApiGatewayTimeoutError( + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, GatewayTimeoutErrorBody.class)); + } + } catch (JsonProcessingException ignored) { + // unable to map error response, throwing generic error + } + throw new CohereApiApiError( + "Error with status code " + response.code(), + response.code(), + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class)); + } catch (IOException e) { + throw new CohereApiError("Network error executing HTTP request", e); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/requests/V2ChatRequest.java b/src/main/java/com/cohere/api/resources/v2/requests/V2ChatRequest.java new file mode 100644 index 0000000..6db075f --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/requests/V2ChatRequest.java @@ -0,0 +1,729 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.requests; + +import com.cohere.api.core.ObjectMappers; +import com.cohere.api.resources.v2.types.ChatMessage2; +import com.cohere.api.resources.v2.types.CitationOptions; +import com.cohere.api.resources.v2.types.ResponseFormat2; +import com.cohere.api.resources.v2.types.Tool2; +import com.cohere.api.resources.v2.types.V2ChatRequestDocumentsItem; +import com.cohere.api.resources.v2.types.V2ChatRequestSafetyMode; +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 = V2ChatRequest.Builder.class) +public final class V2ChatRequest { + private final String model; + + private final List messages; + + private final Optional> tools; + + private final Optional> documents; + + private final Optional citationOptions; + + private final Optional responseFormat; + + private final Optional safetyMode; + + private final Optional maxTokens; + + private final Optional> stopSequences; + + private final Optional temperature; + + private final Optional seed; + + private final Optional frequencyPenalty; + + private final Optional presencePenalty; + + private final Optional k; + + private final Optional p; + + private final Optional returnPrompt; + + private final Map additionalProperties; + + private V2ChatRequest( + String model, + List messages, + Optional> tools, + Optional> documents, + Optional citationOptions, + Optional responseFormat, + Optional safetyMode, + Optional maxTokens, + Optional> stopSequences, + Optional temperature, + Optional seed, + Optional frequencyPenalty, + Optional presencePenalty, + Optional k, + Optional p, + Optional returnPrompt, + Map additionalProperties) { + this.model = model; + this.messages = messages; + this.tools = tools; + this.documents = documents; + this.citationOptions = citationOptions; + this.responseFormat = responseFormat; + this.safetyMode = safetyMode; + this.maxTokens = maxTokens; + this.stopSequences = stopSequences; + this.temperature = temperature; + this.seed = seed; + this.frequencyPenalty = frequencyPenalty; + this.presencePenalty = presencePenalty; + this.k = k; + this.p = p; + this.returnPrompt = returnPrompt; + this.additionalProperties = additionalProperties; + } + + /** + * @return The name of a compatible Cohere model (such as command-r or command-r-plus) or the ID of a fine-tuned model. + */ + @JsonProperty("model") + public String getModel() { + return model; + } + + @JsonProperty("messages") + public List getMessages() { + return messages; + } + + /** + * @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 content in the response will be empty 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.

+ */ + @JsonProperty("tools") + public Optional> getTools() { + return tools; + } + + /** + * @return A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata. + */ + @JsonProperty("documents") + public Optional> getDocuments() { + return documents; + } + + @JsonProperty("citation_options") + public Optional getCitationOptions() { + return citationOptions; + } + + @JsonProperty("response_format") + public Optional getResponseFormat() { + return responseFormat; + } + + /** + * @return Used to select the safety instruction inserted into the prompt. Defaults to CONTEXTUAL. + * When NONE is specified, the safety instruction will be omitted. + *

Safety modes are not yet configurable in combination with tools, tool_results and documents parameters.

+ *

Note: This parameter is only compatible with models Command R 08-2024, Command R+ 08-2024 and newer.

+ *

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

+ */ + @JsonProperty("safety_mode") + public Optional getSafetyMode() { + return safetyMode; + } + + /** + * @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. + */ + @JsonProperty("max_tokens") + public Optional getMaxTokens() { + return maxTokens; + } + + /** + * @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. + */ + @JsonProperty("stop_sequences") + public Optional> getStopSequences() { + return stopSequences; + } + + /** + * @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.

+ */ + @JsonProperty("temperature") + public Optional getTemperature() { + return temperature; + } + + /** + * @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. + */ + @JsonProperty("seed") + public Optional getSeed() { + return seed; + } + + /** + * @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. + */ + @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. + */ + @JsonProperty("presence_penalty") + public Optional getPresencePenalty() { + return presencePenalty; + } + + /** + * @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. + */ + @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. + */ + @JsonProperty("p") + public Optional getP() { + return p; + } + + /** + * @return Whether to return the prompt in the response. + */ + @JsonProperty("return_prompt") + public Optional getReturnPrompt() { + return returnPrompt; + } + + @JsonProperty("stream") + public Boolean getStream() { + return false; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof V2ChatRequest && equalTo((V2ChatRequest) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(V2ChatRequest other) { + return model.equals(other.model) + && messages.equals(other.messages) + && tools.equals(other.tools) + && documents.equals(other.documents) + && citationOptions.equals(other.citationOptions) + && responseFormat.equals(other.responseFormat) + && safetyMode.equals(other.safetyMode) + && maxTokens.equals(other.maxTokens) + && stopSequences.equals(other.stopSequences) + && temperature.equals(other.temperature) + && seed.equals(other.seed) + && frequencyPenalty.equals(other.frequencyPenalty) + && presencePenalty.equals(other.presencePenalty) + && k.equals(other.k) + && p.equals(other.p) + && returnPrompt.equals(other.returnPrompt); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash( + this.model, + this.messages, + this.tools, + this.documents, + this.citationOptions, + this.responseFormat, + this.safetyMode, + this.maxTokens, + this.stopSequences, + this.temperature, + this.seed, + this.frequencyPenalty, + this.presencePenalty, + this.k, + this.p, + this.returnPrompt); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static ModelStage builder() { + return new Builder(); + } + + public interface ModelStage { + _FinalStage model(String model); + + Builder from(V2ChatRequest other); + } + + public interface _FinalStage { + V2ChatRequest build(); + + _FinalStage messages(List messages); + + _FinalStage addMessages(ChatMessage2 messages); + + _FinalStage addAllMessages(List messages); + + _FinalStage tools(Optional> tools); + + _FinalStage tools(List tools); + + _FinalStage documents(Optional> documents); + + _FinalStage documents(List documents); + + _FinalStage citationOptions(Optional citationOptions); + + _FinalStage citationOptions(CitationOptions citationOptions); + + _FinalStage responseFormat(Optional responseFormat); + + _FinalStage responseFormat(ResponseFormat2 responseFormat); + + _FinalStage safetyMode(Optional safetyMode); + + _FinalStage safetyMode(V2ChatRequestSafetyMode safetyMode); + + _FinalStage maxTokens(Optional maxTokens); + + _FinalStage maxTokens(Integer maxTokens); + + _FinalStage stopSequences(Optional> stopSequences); + + _FinalStage stopSequences(List stopSequences); + + _FinalStage temperature(Optional temperature); + + _FinalStage temperature(Double temperature); + + _FinalStage seed(Optional seed); + + _FinalStage seed(Integer seed); + + _FinalStage frequencyPenalty(Optional frequencyPenalty); + + _FinalStage frequencyPenalty(Double frequencyPenalty); + + _FinalStage presencePenalty(Optional presencePenalty); + + _FinalStage presencePenalty(Double presencePenalty); + + _FinalStage k(Optional k); + + _FinalStage k(Double k); + + _FinalStage p(Optional p); + + _FinalStage p(Double p); + + _FinalStage returnPrompt(Optional returnPrompt); + + _FinalStage returnPrompt(Boolean returnPrompt); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements ModelStage, _FinalStage { + private String model; + + private Optional returnPrompt = Optional.empty(); + + private Optional p = Optional.empty(); + + private Optional k = Optional.empty(); + + private Optional presencePenalty = Optional.empty(); + + private Optional frequencyPenalty = Optional.empty(); + + private Optional seed = Optional.empty(); + + private Optional temperature = Optional.empty(); + + private Optional> stopSequences = Optional.empty(); + + private Optional maxTokens = Optional.empty(); + + private Optional safetyMode = Optional.empty(); + + private Optional responseFormat = Optional.empty(); + + private Optional citationOptions = Optional.empty(); + + private Optional> documents = Optional.empty(); + + private Optional> tools = Optional.empty(); + + private List messages = new ArrayList<>(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(V2ChatRequest other) { + model(other.getModel()); + messages(other.getMessages()); + tools(other.getTools()); + documents(other.getDocuments()); + citationOptions(other.getCitationOptions()); + responseFormat(other.getResponseFormat()); + safetyMode(other.getSafetyMode()); + maxTokens(other.getMaxTokens()); + stopSequences(other.getStopSequences()); + temperature(other.getTemperature()); + seed(other.getSeed()); + frequencyPenalty(other.getFrequencyPenalty()); + presencePenalty(other.getPresencePenalty()); + k(other.getK()); + p(other.getP()); + returnPrompt(other.getReturnPrompt()); + return this; + } + + /** + *

The name of a compatible Cohere model (such as command-r or command-r-plus) or the ID of a fine-tuned model.

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

Whether to return the prompt in the response.

+ * @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; + } + + /** + *

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.

+ * @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.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage k(Double 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; + } + + /** + *

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.

+ * @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.

+ * @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; + } + + /** + *

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.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage seed(Integer 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; + } + + /** + *

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.

+ * @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; + } + + /** + *

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.

+ * @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; + } + + /** + *

The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations.

+ * @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; + } + + /** + *

Used to select the safety instruction inserted into the prompt. Defaults to CONTEXTUAL. + * When NONE is specified, the safety instruction will be omitted.

+ *

Safety modes are not yet configurable in combination with tools, tool_results and documents parameters.

+ *

Note: This parameter is only compatible with models Command R 08-2024, Command R+ 08-2024 and newer.

+ *

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage safetyMode(V2ChatRequestSafetyMode safetyMode) { + this.safetyMode = Optional.of(safetyMode); + return this; + } + + @java.lang.Override + @JsonSetter(value = "safety_mode", nulls = Nulls.SKIP) + public _FinalStage safetyMode(Optional safetyMode) { + this.safetyMode = safetyMode; + return this; + } + + @java.lang.Override + public _FinalStage responseFormat(ResponseFormat2 responseFormat) { + this.responseFormat = Optional.of(responseFormat); + return this; + } + + @java.lang.Override + @JsonSetter(value = "response_format", nulls = Nulls.SKIP) + public _FinalStage responseFormat(Optional responseFormat) { + this.responseFormat = responseFormat; + return this; + } + + @java.lang.Override + public _FinalStage citationOptions(CitationOptions citationOptions) { + this.citationOptions = Optional.of(citationOptions); + return this; + } + + @java.lang.Override + @JsonSetter(value = "citation_options", nulls = Nulls.SKIP) + public _FinalStage citationOptions(Optional citationOptions) { + this.citationOptions = citationOptions; + return this; + } + + /** + *

A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata.

+ * @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; + } + + /** + *

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 content in the response will be empty 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.

+ * @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; + } + + @java.lang.Override + public _FinalStage addAllMessages(List messages) { + this.messages.addAll(messages); + return this; + } + + @java.lang.Override + public _FinalStage addMessages(ChatMessage2 messages) { + this.messages.add(messages); + return this; + } + + @java.lang.Override + @JsonSetter(value = "messages", nulls = Nulls.SKIP) + public _FinalStage messages(List messages) { + this.messages.clear(); + this.messages.addAll(messages); + return this; + } + + @java.lang.Override + public V2ChatRequest build() { + return new V2ChatRequest( + model, + messages, + tools, + documents, + citationOptions, + responseFormat, + safetyMode, + maxTokens, + stopSequences, + temperature, + seed, + frequencyPenalty, + presencePenalty, + k, + p, + returnPrompt, + additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/requests/V2ChatStreamRequest.java b/src/main/java/com/cohere/api/resources/v2/requests/V2ChatStreamRequest.java new file mode 100644 index 0000000..a042d31 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/requests/V2ChatStreamRequest.java @@ -0,0 +1,729 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.requests; + +import com.cohere.api.core.ObjectMappers; +import com.cohere.api.resources.v2.types.ChatMessage2; +import com.cohere.api.resources.v2.types.CitationOptions; +import com.cohere.api.resources.v2.types.ResponseFormat2; +import com.cohere.api.resources.v2.types.Tool2; +import com.cohere.api.resources.v2.types.V2ChatStreamRequestDocumentsItem; +import com.cohere.api.resources.v2.types.V2ChatStreamRequestSafetyMode; +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 = V2ChatStreamRequest.Builder.class) +public final class V2ChatStreamRequest { + private final String model; + + private final List messages; + + private final Optional> tools; + + private final Optional> documents; + + private final Optional citationOptions; + + private final Optional responseFormat; + + private final Optional safetyMode; + + private final Optional maxTokens; + + private final Optional> stopSequences; + + private final Optional temperature; + + private final Optional seed; + + private final Optional frequencyPenalty; + + private final Optional presencePenalty; + + private final Optional k; + + private final Optional p; + + private final Optional returnPrompt; + + private final Map additionalProperties; + + private V2ChatStreamRequest( + String model, + List messages, + Optional> tools, + Optional> documents, + Optional citationOptions, + Optional responseFormat, + Optional safetyMode, + Optional maxTokens, + Optional> stopSequences, + Optional temperature, + Optional seed, + Optional frequencyPenalty, + Optional presencePenalty, + Optional k, + Optional p, + Optional returnPrompt, + Map additionalProperties) { + this.model = model; + this.messages = messages; + this.tools = tools; + this.documents = documents; + this.citationOptions = citationOptions; + this.responseFormat = responseFormat; + this.safetyMode = safetyMode; + this.maxTokens = maxTokens; + this.stopSequences = stopSequences; + this.temperature = temperature; + this.seed = seed; + this.frequencyPenalty = frequencyPenalty; + this.presencePenalty = presencePenalty; + this.k = k; + this.p = p; + this.returnPrompt = returnPrompt; + this.additionalProperties = additionalProperties; + } + + /** + * @return The name of a compatible Cohere model (such as command-r or command-r-plus) or the ID of a fine-tuned model. + */ + @JsonProperty("model") + public String getModel() { + return model; + } + + @JsonProperty("messages") + public List getMessages() { + return messages; + } + + /** + * @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 content in the response will be empty 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.

+ */ + @JsonProperty("tools") + public Optional> getTools() { + return tools; + } + + /** + * @return A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata. + */ + @JsonProperty("documents") + public Optional> getDocuments() { + return documents; + } + + @JsonProperty("citation_options") + public Optional getCitationOptions() { + return citationOptions; + } + + @JsonProperty("response_format") + public Optional getResponseFormat() { + return responseFormat; + } + + /** + * @return Used to select the safety instruction inserted into the prompt. Defaults to CONTEXTUAL. + * When NONE is specified, the safety instruction will be omitted. + *

Safety modes are not yet configurable in combination with tools, tool_results and documents parameters.

+ *

Note: This parameter is only compatible with models Command R 08-2024, Command R+ 08-2024 and newer.

+ *

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

+ */ + @JsonProperty("safety_mode") + public Optional getSafetyMode() { + return safetyMode; + } + + /** + * @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. + */ + @JsonProperty("max_tokens") + public Optional getMaxTokens() { + return maxTokens; + } + + /** + * @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. + */ + @JsonProperty("stop_sequences") + public Optional> getStopSequences() { + return stopSequences; + } + + /** + * @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.

+ */ + @JsonProperty("temperature") + public Optional getTemperature() { + return temperature; + } + + /** + * @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. + */ + @JsonProperty("seed") + public Optional getSeed() { + return seed; + } + + /** + * @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. + */ + @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. + */ + @JsonProperty("presence_penalty") + public Optional getPresencePenalty() { + return presencePenalty; + } + + /** + * @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. + */ + @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. + */ + @JsonProperty("p") + public Optional getP() { + return p; + } + + /** + * @return Whether to return the prompt in the response. + */ + @JsonProperty("return_prompt") + public Optional getReturnPrompt() { + return returnPrompt; + } + + @JsonProperty("stream") + public Boolean getStream() { + return true; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof V2ChatStreamRequest && equalTo((V2ChatStreamRequest) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(V2ChatStreamRequest other) { + return model.equals(other.model) + && messages.equals(other.messages) + && tools.equals(other.tools) + && documents.equals(other.documents) + && citationOptions.equals(other.citationOptions) + && responseFormat.equals(other.responseFormat) + && safetyMode.equals(other.safetyMode) + && maxTokens.equals(other.maxTokens) + && stopSequences.equals(other.stopSequences) + && temperature.equals(other.temperature) + && seed.equals(other.seed) + && frequencyPenalty.equals(other.frequencyPenalty) + && presencePenalty.equals(other.presencePenalty) + && k.equals(other.k) + && p.equals(other.p) + && returnPrompt.equals(other.returnPrompt); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash( + this.model, + this.messages, + this.tools, + this.documents, + this.citationOptions, + this.responseFormat, + this.safetyMode, + this.maxTokens, + this.stopSequences, + this.temperature, + this.seed, + this.frequencyPenalty, + this.presencePenalty, + this.k, + this.p, + this.returnPrompt); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static ModelStage builder() { + return new Builder(); + } + + public interface ModelStage { + _FinalStage model(String model); + + Builder from(V2ChatStreamRequest other); + } + + public interface _FinalStage { + V2ChatStreamRequest build(); + + _FinalStage messages(List messages); + + _FinalStage addMessages(ChatMessage2 messages); + + _FinalStage addAllMessages(List messages); + + _FinalStage tools(Optional> tools); + + _FinalStage tools(List tools); + + _FinalStage documents(Optional> documents); + + _FinalStage documents(List documents); + + _FinalStage citationOptions(Optional citationOptions); + + _FinalStage citationOptions(CitationOptions citationOptions); + + _FinalStage responseFormat(Optional responseFormat); + + _FinalStage responseFormat(ResponseFormat2 responseFormat); + + _FinalStage safetyMode(Optional safetyMode); + + _FinalStage safetyMode(V2ChatStreamRequestSafetyMode safetyMode); + + _FinalStage maxTokens(Optional maxTokens); + + _FinalStage maxTokens(Integer maxTokens); + + _FinalStage stopSequences(Optional> stopSequences); + + _FinalStage stopSequences(List stopSequences); + + _FinalStage temperature(Optional temperature); + + _FinalStage temperature(Double temperature); + + _FinalStage seed(Optional seed); + + _FinalStage seed(Integer seed); + + _FinalStage frequencyPenalty(Optional frequencyPenalty); + + _FinalStage frequencyPenalty(Double frequencyPenalty); + + _FinalStage presencePenalty(Optional presencePenalty); + + _FinalStage presencePenalty(Double presencePenalty); + + _FinalStage k(Optional k); + + _FinalStage k(Double k); + + _FinalStage p(Optional p); + + _FinalStage p(Double p); + + _FinalStage returnPrompt(Optional returnPrompt); + + _FinalStage returnPrompt(Boolean returnPrompt); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements ModelStage, _FinalStage { + private String model; + + private Optional returnPrompt = Optional.empty(); + + private Optional p = Optional.empty(); + + private Optional k = Optional.empty(); + + private Optional presencePenalty = Optional.empty(); + + private Optional frequencyPenalty = Optional.empty(); + + private Optional seed = Optional.empty(); + + private Optional temperature = Optional.empty(); + + private Optional> stopSequences = Optional.empty(); + + private Optional maxTokens = Optional.empty(); + + private Optional safetyMode = Optional.empty(); + + private Optional responseFormat = Optional.empty(); + + private Optional citationOptions = Optional.empty(); + + private Optional> documents = Optional.empty(); + + private Optional> tools = Optional.empty(); + + private List messages = new ArrayList<>(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(V2ChatStreamRequest other) { + model(other.getModel()); + messages(other.getMessages()); + tools(other.getTools()); + documents(other.getDocuments()); + citationOptions(other.getCitationOptions()); + responseFormat(other.getResponseFormat()); + safetyMode(other.getSafetyMode()); + maxTokens(other.getMaxTokens()); + stopSequences(other.getStopSequences()); + temperature(other.getTemperature()); + seed(other.getSeed()); + frequencyPenalty(other.getFrequencyPenalty()); + presencePenalty(other.getPresencePenalty()); + k(other.getK()); + p(other.getP()); + returnPrompt(other.getReturnPrompt()); + return this; + } + + /** + *

The name of a compatible Cohere model (such as command-r or command-r-plus) or the ID of a fine-tuned model.

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

Whether to return the prompt in the response.

+ * @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; + } + + /** + *

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.

+ * @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.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage k(Double 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; + } + + /** + *

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.

+ * @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.

+ * @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; + } + + /** + *

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.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage seed(Integer 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; + } + + /** + *

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.

+ * @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; + } + + /** + *

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.

+ * @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; + } + + /** + *

The maximum number of tokens the model will generate as part of the response. Note: Setting a low value may result in incomplete generations.

+ * @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; + } + + /** + *

Used to select the safety instruction inserted into the prompt. Defaults to CONTEXTUAL. + * When NONE is specified, the safety instruction will be omitted.

+ *

Safety modes are not yet configurable in combination with tools, tool_results and documents parameters.

+ *

Note: This parameter is only compatible with models Command R 08-2024, Command R+ 08-2024 and newer.

+ *

Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker/Bedrock, Private Deployments

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage safetyMode(V2ChatStreamRequestSafetyMode safetyMode) { + this.safetyMode = Optional.of(safetyMode); + return this; + } + + @java.lang.Override + @JsonSetter(value = "safety_mode", nulls = Nulls.SKIP) + public _FinalStage safetyMode(Optional safetyMode) { + this.safetyMode = safetyMode; + return this; + } + + @java.lang.Override + public _FinalStage responseFormat(ResponseFormat2 responseFormat) { + this.responseFormat = Optional.of(responseFormat); + return this; + } + + @java.lang.Override + @JsonSetter(value = "response_format", nulls = Nulls.SKIP) + public _FinalStage responseFormat(Optional responseFormat) { + this.responseFormat = responseFormat; + return this; + } + + @java.lang.Override + public _FinalStage citationOptions(CitationOptions citationOptions) { + this.citationOptions = Optional.of(citationOptions); + return this; + } + + @java.lang.Override + @JsonSetter(value = "citation_options", nulls = Nulls.SKIP) + public _FinalStage citationOptions(Optional citationOptions) { + this.citationOptions = citationOptions; + return this; + } + + /** + *

A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata.

+ * @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; + } + + /** + *

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 content in the response will be empty 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.

+ * @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; + } + + @java.lang.Override + public _FinalStage addAllMessages(List messages) { + this.messages.addAll(messages); + return this; + } + + @java.lang.Override + public _FinalStage addMessages(ChatMessage2 messages) { + this.messages.add(messages); + return this; + } + + @java.lang.Override + @JsonSetter(value = "messages", nulls = Nulls.SKIP) + public _FinalStage messages(List messages) { + this.messages.clear(); + this.messages.addAll(messages); + return this; + } + + @java.lang.Override + public V2ChatStreamRequest build() { + return new V2ChatStreamRequest( + model, + messages, + tools, + documents, + citationOptions, + responseFormat, + safetyMode, + maxTokens, + stopSequences, + temperature, + seed, + frequencyPenalty, + presencePenalty, + k, + p, + returnPrompt, + additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/AssistantMessage.java b/src/main/java/com/cohere/api/resources/v2/types/AssistantMessage.java new file mode 100644 index 0000000..a04ebbc --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/AssistantMessage.java @@ -0,0 +1,170 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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 = AssistantMessage.Builder.class) +public final class AssistantMessage { + private final Optional> toolCalls; + + private final Optional toolPlan; + + private final Optional content; + + private final Optional> citations; + + private final Map additionalProperties; + + private AssistantMessage( + Optional> toolCalls, + Optional toolPlan, + Optional content, + Optional> citations, + Map additionalProperties) { + this.toolCalls = toolCalls; + this.toolPlan = toolPlan; + this.content = content; + this.citations = citations; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("tool_calls") + public Optional> getToolCalls() { + return toolCalls; + } + + @JsonProperty("tool_plan") + public Optional getToolPlan() { + return toolPlan; + } + + @JsonProperty("content") + public Optional getContent() { + return content; + } + + @JsonProperty("citations") + public Optional> getCitations() { + return citations; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof AssistantMessage && equalTo((AssistantMessage) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(AssistantMessage other) { + return toolCalls.equals(other.toolCalls) + && toolPlan.equals(other.toolPlan) + && content.equals(other.content) + && citations.equals(other.citations); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.toolCalls, this.toolPlan, this.content, this.citations); + } + + @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 Optional> toolCalls = Optional.empty(); + + private Optional toolPlan = Optional.empty(); + + private Optional content = Optional.empty(); + + private Optional> citations = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(AssistantMessage other) { + toolCalls(other.getToolCalls()); + toolPlan(other.getToolPlan()); + content(other.getContent()); + citations(other.getCitations()); + return this; + } + + @JsonSetter(value = "tool_calls", nulls = Nulls.SKIP) + public Builder toolCalls(Optional> toolCalls) { + this.toolCalls = toolCalls; + return this; + } + + public Builder toolCalls(List toolCalls) { + this.toolCalls = Optional.of(toolCalls); + return this; + } + + @JsonSetter(value = "tool_plan", nulls = Nulls.SKIP) + public Builder toolPlan(Optional toolPlan) { + this.toolPlan = toolPlan; + return this; + } + + public Builder toolPlan(String toolPlan) { + this.toolPlan = Optional.of(toolPlan); + return this; + } + + @JsonSetter(value = "content", nulls = Nulls.SKIP) + public Builder content(Optional content) { + this.content = content; + return this; + } + + public Builder content(AssistantMessageContent content) { + this.content = Optional.of(content); + return this; + } + + @JsonSetter(value = "citations", nulls = Nulls.SKIP) + public Builder citations(Optional> citations) { + this.citations = citations; + return this; + } + + public Builder citations(List citations) { + this.citations = Optional.of(citations); + return this; + } + + public AssistantMessage build() { + return new AssistantMessage(toolCalls, toolPlan, content, citations, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageContent.java b/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageContent.java new file mode 100644 index 0000000..47c0c48 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageContent.java @@ -0,0 +1,97 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import java.io.IOException; +import java.util.List; +import java.util.Objects; + +@JsonDeserialize(using = AssistantMessageContent.Deserializer.class) +public final class AssistantMessageContent { + private final Object value; + + private final int type; + + private AssistantMessageContent(Object value, int type) { + this.value = value; + this.type = type; + } + + @JsonValue + public Object get() { + return this.value; + } + + public T visit(Visitor visitor) { + if (this.type == 0) { + return visitor.visit((String) this.value); + } else if (this.type == 1) { + return visitor.visit((List) this.value); + } + throw new IllegalStateException("Failed to visit value. This should never happen."); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof AssistantMessageContent && equalTo((AssistantMessageContent) other); + } + + private boolean equalTo(AssistantMessageContent other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return this.value.toString(); + } + + public static AssistantMessageContent of(String value) { + return new AssistantMessageContent(value, 0); + } + + public static AssistantMessageContent of(List value) { + return new AssistantMessageContent(value, 1); + } + + public interface Visitor { + T visit(String value); + + T visit(List value); + } + + static final class Deserializer extends StdDeserializer { + Deserializer() { + super(AssistantMessageContent.class); + } + + @java.lang.Override + public AssistantMessageContent deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + Object value = p.readValueAs(Object.class); + try { + return of(ObjectMappers.JSON_MAPPER.convertValue(value, String.class)); + } catch (IllegalArgumentException e) { + } + try { + return of(ObjectMappers.JSON_MAPPER.convertValue( + value, new TypeReference>() {})); + } catch (IllegalArgumentException e) { + } + throw new JsonParseException(p, "Failed to deserialize"); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageContentItem.java b/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageContentItem.java new file mode 100644 index 0000000..7287f41 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageContentItem.java @@ -0,0 +1,145 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Objects; +import java.util.Optional; + +public final class AssistantMessageContentItem { + private final Value value; + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private AssistantMessageContentItem(Value value) { + this.value = value; + } + + public T visit(Visitor visitor) { + return value.visit(visitor); + } + + public static AssistantMessageContentItem text(TextContent value) { + return new AssistantMessageContentItem(new TextValue(value)); + } + + public boolean isText() { + return value instanceof TextValue; + } + + public boolean _isUnknown() { + return value instanceof _UnknownValue; + } + + public Optional getText() { + if (isText()) { + return Optional.of(((TextValue) value).value); + } + return Optional.empty(); + } + + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); + } + + @JsonValue + private Value getValue() { + return this.value; + } + + public interface Visitor { + T visitText(TextContent text); + + T _visitUnknown(Object unknownType); + } + + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = _UnknownValue.class) + @JsonSubTypes(@JsonSubTypes.Type(TextValue.class)) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } + + @JsonTypeName("text") + private static final class TextValue implements Value { + @JsonUnwrapped + private TextContent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private TextValue() {} + + private TextValue(TextContent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitText(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof TextValue && equalTo((TextValue) other); + } + + private boolean equalTo(TextValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "AssistantMessageContentItem{" + "value: " + value + "}"; + } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); + } + + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @java.lang.Override + public String toString() { + return "AssistantMessageContentItem{" + "type: " + type + ", value: " + value + "}"; + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageResponse.java b/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageResponse.java new file mode 100644 index 0000000..17d69b4 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageResponse.java @@ -0,0 +1,175 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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 = AssistantMessageResponse.Builder.class) +public final class AssistantMessageResponse { + private final Optional> toolCalls; + + private final Optional toolPlan; + + private final Optional> content; + + private final Optional> citations; + + private final Map additionalProperties; + + private AssistantMessageResponse( + Optional> toolCalls, + Optional toolPlan, + Optional> content, + Optional> citations, + Map additionalProperties) { + this.toolCalls = toolCalls; + this.toolPlan = toolPlan; + this.content = content; + this.citations = citations; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("role") + public String getRole() { + return "assistant"; + } + + @JsonProperty("tool_calls") + public Optional> getToolCalls() { + return toolCalls; + } + + @JsonProperty("tool_plan") + public Optional getToolPlan() { + return toolPlan; + } + + @JsonProperty("content") + public Optional> getContent() { + return content; + } + + @JsonProperty("citations") + public Optional> getCitations() { + return citations; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof AssistantMessageResponse && equalTo((AssistantMessageResponse) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(AssistantMessageResponse other) { + return toolCalls.equals(other.toolCalls) + && toolPlan.equals(other.toolPlan) + && content.equals(other.content) + && citations.equals(other.citations); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.toolCalls, this.toolPlan, this.content, this.citations); + } + + @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 Optional> toolCalls = Optional.empty(); + + private Optional toolPlan = Optional.empty(); + + private Optional> content = Optional.empty(); + + private Optional> citations = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(AssistantMessageResponse other) { + toolCalls(other.getToolCalls()); + toolPlan(other.getToolPlan()); + content(other.getContent()); + citations(other.getCitations()); + return this; + } + + @JsonSetter(value = "tool_calls", nulls = Nulls.SKIP) + public Builder toolCalls(Optional> toolCalls) { + this.toolCalls = toolCalls; + return this; + } + + public Builder toolCalls(List toolCalls) { + this.toolCalls = Optional.of(toolCalls); + return this; + } + + @JsonSetter(value = "tool_plan", nulls = Nulls.SKIP) + public Builder toolPlan(Optional toolPlan) { + this.toolPlan = toolPlan; + return this; + } + + public Builder toolPlan(String toolPlan) { + this.toolPlan = Optional.of(toolPlan); + return this; + } + + @JsonSetter(value = "content", nulls = Nulls.SKIP) + public Builder content(Optional> content) { + this.content = content; + return this; + } + + public Builder content(List content) { + this.content = Optional.of(content); + return this; + } + + @JsonSetter(value = "citations", nulls = Nulls.SKIP) + public Builder citations(Optional> citations) { + this.citations = citations; + return this; + } + + public Builder citations(List citations) { + this.citations = Optional.of(citations); + return this; + } + + public AssistantMessageResponse build() { + return new AssistantMessageResponse(toolCalls, toolPlan, content, citations, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageResponseContentItem.java b/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageResponseContentItem.java new file mode 100644 index 0000000..c6b7cfc --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/AssistantMessageResponseContentItem.java @@ -0,0 +1,145 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Objects; +import java.util.Optional; + +public final class AssistantMessageResponseContentItem { + private final Value value; + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private AssistantMessageResponseContentItem(Value value) { + this.value = value; + } + + public T visit(Visitor visitor) { + return value.visit(visitor); + } + + public static AssistantMessageResponseContentItem text(TextContent value) { + return new AssistantMessageResponseContentItem(new TextValue(value)); + } + + public boolean isText() { + return value instanceof TextValue; + } + + public boolean _isUnknown() { + return value instanceof _UnknownValue; + } + + public Optional getText() { + if (isText()) { + return Optional.of(((TextValue) value).value); + } + return Optional.empty(); + } + + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); + } + + @JsonValue + private Value getValue() { + return this.value; + } + + public interface Visitor { + T visitText(TextContent text); + + T _visitUnknown(Object unknownType); + } + + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = _UnknownValue.class) + @JsonSubTypes(@JsonSubTypes.Type(TextValue.class)) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } + + @JsonTypeName("text") + private static final class TextValue implements Value { + @JsonUnwrapped + private TextContent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private TextValue() {} + + private TextValue(TextContent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitText(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof TextValue && equalTo((TextValue) other); + } + + private boolean equalTo(TextValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "AssistantMessageResponseContentItem{" + "value: " + value + "}"; + } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); + } + + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @java.lang.Override + public String toString() { + return "AssistantMessageResponseContentItem{" + "type: " + type + ", value: " + value + "}"; + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEvent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEvent.java new file mode 100644 index 0000000..e9af831 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEvent.java @@ -0,0 +1,120 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatContentDeltaEvent.Builder.class) +public final class ChatContentDeltaEvent implements IChatStreamEventType { + private final Optional index; + + private final Optional delta; + + private final Map additionalProperties; + + private ChatContentDeltaEvent( + Optional index, + Optional delta, + Map additionalProperties) { + this.index = index; + this.delta = delta; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("index") + public Optional getIndex() { + return index; + } + + @JsonProperty("delta") + public Optional getDelta() { + return delta; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatContentDeltaEvent && equalTo((ChatContentDeltaEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatContentDeltaEvent other) { + return index.equals(other.index) && delta.equals(other.delta); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.index, this.delta); + } + + @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 Optional index = Optional.empty(); + + private Optional delta = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatContentDeltaEvent other) { + index(other.getIndex()); + delta(other.getDelta()); + return this; + } + + @JsonSetter(value = "index", nulls = Nulls.SKIP) + public Builder index(Optional index) { + this.index = index; + return this; + } + + public Builder index(Integer index) { + this.index = Optional.of(index); + return this; + } + + @JsonSetter(value = "delta", nulls = Nulls.SKIP) + public Builder delta(Optional delta) { + this.delta = delta; + return this; + } + + public Builder delta(ChatContentDeltaEventDelta delta) { + this.delta = Optional.of(delta); + return this; + } + + public ChatContentDeltaEvent build() { + return new ChatContentDeltaEvent(index, delta, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDelta.java b/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDelta.java new file mode 100644 index 0000000..f4c3cee --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDelta.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatContentDeltaEventDelta.Builder.class) +public final class ChatContentDeltaEventDelta { + private final Optional message; + + private final Map additionalProperties; + + private ChatContentDeltaEventDelta( + Optional message, Map additionalProperties) { + this.message = message; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("message") + public Optional getMessage() { + return message; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatContentDeltaEventDelta && equalTo((ChatContentDeltaEventDelta) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatContentDeltaEventDelta other) { + return message.equals(other.message); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.message); + } + + @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 Optional message = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatContentDeltaEventDelta other) { + message(other.getMessage()); + return this; + } + + @JsonSetter(value = "message", nulls = Nulls.SKIP) + public Builder message(Optional message) { + this.message = message; + return this; + } + + public Builder message(ChatContentDeltaEventDeltaMessage message) { + this.message = Optional.of(message); + return this; + } + + public ChatContentDeltaEventDelta build() { + return new ChatContentDeltaEventDelta(message, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDeltaMessage.java b/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDeltaMessage.java new file mode 100644 index 0000000..3f8c547 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDeltaMessage.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatContentDeltaEventDeltaMessage.Builder.class) +public final class ChatContentDeltaEventDeltaMessage { + private final Optional content; + + private final Map additionalProperties; + + private ChatContentDeltaEventDeltaMessage( + Optional content, Map additionalProperties) { + this.content = content; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("content") + public Optional getContent() { + return content; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatContentDeltaEventDeltaMessage && equalTo((ChatContentDeltaEventDeltaMessage) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatContentDeltaEventDeltaMessage other) { + return content.equals(other.content); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.content); + } + + @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 Optional content = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatContentDeltaEventDeltaMessage other) { + content(other.getContent()); + return this; + } + + @JsonSetter(value = "content", nulls = Nulls.SKIP) + public Builder content(Optional content) { + this.content = content; + return this; + } + + public Builder content(ChatContentDeltaEventDeltaMessageContent content) { + this.content = Optional.of(content); + return this; + } + + public ChatContentDeltaEventDeltaMessage build() { + return new ChatContentDeltaEventDeltaMessage(content, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDeltaMessageContent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDeltaMessageContent.java new file mode 100644 index 0000000..fe5b95b --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatContentDeltaEventDeltaMessageContent.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatContentDeltaEventDeltaMessageContent.Builder.class) +public final class ChatContentDeltaEventDeltaMessageContent { + private final Optional text; + + private final Map additionalProperties; + + private ChatContentDeltaEventDeltaMessageContent(Optional text, Map additionalProperties) { + this.text = text; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("text") + public Optional getText() { + return text; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatContentDeltaEventDeltaMessageContent + && equalTo((ChatContentDeltaEventDeltaMessageContent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatContentDeltaEventDeltaMessageContent other) { + return text.equals(other.text); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.text); + } + + @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 Optional text = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatContentDeltaEventDeltaMessageContent other) { + text(other.getText()); + return this; + } + + @JsonSetter(value = "text", nulls = Nulls.SKIP) + public Builder text(Optional text) { + this.text = text; + return this; + } + + public Builder text(String text) { + this.text = Optional.of(text); + return this; + } + + public ChatContentDeltaEventDeltaMessageContent build() { + return new ChatContentDeltaEventDeltaMessageContent(text, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatContentEndEvent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatContentEndEvent.java new file mode 100644 index 0000000..cfcaec2 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatContentEndEvent.java @@ -0,0 +1,95 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatContentEndEvent.Builder.class) +public final class ChatContentEndEvent implements IChatStreamEventType { + private final Optional index; + + private final Map additionalProperties; + + private ChatContentEndEvent(Optional index, Map additionalProperties) { + this.index = index; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("index") + public Optional getIndex() { + return index; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatContentEndEvent && equalTo((ChatContentEndEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatContentEndEvent other) { + return index.equals(other.index); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.index); + } + + @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 Optional index = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatContentEndEvent other) { + index(other.getIndex()); + return this; + } + + @JsonSetter(value = "index", nulls = Nulls.SKIP) + public Builder index(Optional index) { + this.index = index; + return this; + } + + public Builder index(Integer index) { + this.index = Optional.of(index); + return this; + } + + public ChatContentEndEvent build() { + return new ChatContentEndEvent(index, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEvent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEvent.java new file mode 100644 index 0000000..7c490ec --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEvent.java @@ -0,0 +1,120 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatContentStartEvent.Builder.class) +public final class ChatContentStartEvent implements IChatStreamEventType { + private final Optional index; + + private final Optional delta; + + private final Map additionalProperties; + + private ChatContentStartEvent( + Optional index, + Optional delta, + Map additionalProperties) { + this.index = index; + this.delta = delta; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("index") + public Optional getIndex() { + return index; + } + + @JsonProperty("delta") + public Optional getDelta() { + return delta; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatContentStartEvent && equalTo((ChatContentStartEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatContentStartEvent other) { + return index.equals(other.index) && delta.equals(other.delta); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.index, this.delta); + } + + @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 Optional index = Optional.empty(); + + private Optional delta = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatContentStartEvent other) { + index(other.getIndex()); + delta(other.getDelta()); + return this; + } + + @JsonSetter(value = "index", nulls = Nulls.SKIP) + public Builder index(Optional index) { + this.index = index; + return this; + } + + public Builder index(Integer index) { + this.index = Optional.of(index); + return this; + } + + @JsonSetter(value = "delta", nulls = Nulls.SKIP) + public Builder delta(Optional delta) { + this.delta = delta; + return this; + } + + public Builder delta(ChatContentStartEventDelta delta) { + this.delta = Optional.of(delta); + return this; + } + + public ChatContentStartEvent build() { + return new ChatContentStartEvent(index, delta, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDelta.java b/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDelta.java new file mode 100644 index 0000000..d488cc5 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDelta.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatContentStartEventDelta.Builder.class) +public final class ChatContentStartEventDelta { + private final Optional message; + + private final Map additionalProperties; + + private ChatContentStartEventDelta( + Optional message, Map additionalProperties) { + this.message = message; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("message") + public Optional getMessage() { + return message; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatContentStartEventDelta && equalTo((ChatContentStartEventDelta) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatContentStartEventDelta other) { + return message.equals(other.message); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.message); + } + + @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 Optional message = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatContentStartEventDelta other) { + message(other.getMessage()); + return this; + } + + @JsonSetter(value = "message", nulls = Nulls.SKIP) + public Builder message(Optional message) { + this.message = message; + return this; + } + + public Builder message(ChatContentStartEventDeltaMessage message) { + this.message = Optional.of(message); + return this; + } + + public ChatContentStartEventDelta build() { + return new ChatContentStartEventDelta(message, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDeltaMessage.java b/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDeltaMessage.java new file mode 100644 index 0000000..3c1a68a --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDeltaMessage.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatContentStartEventDeltaMessage.Builder.class) +public final class ChatContentStartEventDeltaMessage { + private final Optional content; + + private final Map additionalProperties; + + private ChatContentStartEventDeltaMessage( + Optional content, Map additionalProperties) { + this.content = content; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("content") + public Optional getContent() { + return content; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatContentStartEventDeltaMessage && equalTo((ChatContentStartEventDeltaMessage) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatContentStartEventDeltaMessage other) { + return content.equals(other.content); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.content); + } + + @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 Optional content = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatContentStartEventDeltaMessage other) { + content(other.getContent()); + return this; + } + + @JsonSetter(value = "content", nulls = Nulls.SKIP) + public Builder content(Optional content) { + this.content = content; + return this; + } + + public Builder content(ChatContentStartEventDeltaMessageContent content) { + this.content = Optional.of(content); + return this; + } + + public ChatContentStartEventDeltaMessage build() { + return new ChatContentStartEventDeltaMessage(content, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDeltaMessageContent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDeltaMessageContent.java new file mode 100644 index 0000000..127f226 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatContentStartEventDeltaMessageContent.java @@ -0,0 +1,119 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatContentStartEventDeltaMessageContent.Builder.class) +public final class ChatContentStartEventDeltaMessageContent { + private final Optional text; + + private final Optional type; + + private final Map additionalProperties; + + private ChatContentStartEventDeltaMessageContent( + Optional text, Optional type, Map additionalProperties) { + this.text = text; + this.type = type; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("text") + public Optional getText() { + return text; + } + + @JsonProperty("type") + public Optional getType() { + return type; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatContentStartEventDeltaMessageContent + && equalTo((ChatContentStartEventDeltaMessageContent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatContentStartEventDeltaMessageContent other) { + return text.equals(other.text) && type.equals(other.type); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.text, this.type); + } + + @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 Optional text = Optional.empty(); + + private Optional type = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatContentStartEventDeltaMessageContent other) { + text(other.getText()); + type(other.getType()); + return this; + } + + @JsonSetter(value = "text", nulls = Nulls.SKIP) + public Builder text(Optional text) { + this.text = text; + return this; + } + + public Builder text(String text) { + this.text = Optional.of(text); + return this; + } + + @JsonSetter(value = "type", nulls = Nulls.SKIP) + public Builder type(Optional type) { + this.type = type; + return this; + } + + public Builder type(String type) { + this.type = Optional.of(type); + return this; + } + + public ChatContentStartEventDeltaMessageContent build() { + return new ChatContentStartEventDeltaMessageContent(text, type, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatFinishReason.java b/src/main/java/com/cohere/api/resources/v2/types/ChatFinishReason.java new file mode 100644 index 0000000..3abaed4 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatFinishReason.java @@ -0,0 +1,34 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum ChatFinishReason { + COMPLETE("complete"), + + STOP_SEQUENCE("stop_sequence"), + + MAX_TOKENS("max_tokens"), + + TOOL_CALL("tool_call"), + + ERROR("error"), + + CONTENT_BLOCKED("content_blocked"), + + ERROR_LIMIT("error_limit"); + + private final String value; + + ChatFinishReason(String value) { + this.value = value; + } + + @JsonValue + @java.lang.Override + public String toString() { + return this.value; + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatMessage2.java b/src/main/java/com/cohere/api/resources/v2/types/ChatMessage2.java new file mode 100644 index 0000000..1ed7074 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatMessage2.java @@ -0,0 +1,315 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Objects; +import java.util.Optional; + +public final class ChatMessage2 { + private final Value value; + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private ChatMessage2(Value value) { + this.value = value; + } + + public T visit(Visitor visitor) { + return value.visit(visitor); + } + + public static ChatMessage2 user(UserMessage value) { + return new ChatMessage2(new UserValue(value)); + } + + public static ChatMessage2 assistant(AssistantMessage value) { + return new ChatMessage2(new AssistantValue(value)); + } + + public static ChatMessage2 system(SystemMessage value) { + return new ChatMessage2(new SystemValue(value)); + } + + public static ChatMessage2 tool(ToolMessage2 value) { + return new ChatMessage2(new ToolValue(value)); + } + + public boolean isUser() { + return value instanceof UserValue; + } + + public boolean isAssistant() { + return value instanceof AssistantValue; + } + + public boolean isSystem() { + return value instanceof SystemValue; + } + + public boolean isTool() { + return value instanceof ToolValue; + } + + public boolean _isUnknown() { + return value instanceof _UnknownValue; + } + + public Optional getUser() { + if (isUser()) { + return Optional.of(((UserValue) value).value); + } + return Optional.empty(); + } + + public Optional getAssistant() { + if (isAssistant()) { + return Optional.of(((AssistantValue) value).value); + } + return Optional.empty(); + } + + public Optional getSystem() { + if (isSystem()) { + return Optional.of(((SystemValue) value).value); + } + return Optional.empty(); + } + + public Optional getTool() { + if (isTool()) { + return Optional.of(((ToolValue) value).value); + } + return Optional.empty(); + } + + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); + } + + @JsonValue + private Value getValue() { + return this.value; + } + + public interface Visitor { + T visitUser(UserMessage user); + + T visitAssistant(AssistantMessage assistant); + + T visitSystem(SystemMessage system); + + T visitTool(ToolMessage2 tool); + + T _visitUnknown(Object unknownType); + } + + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "role", visible = true, defaultImpl = _UnknownValue.class) + @JsonSubTypes({ + @JsonSubTypes.Type(UserValue.class), + @JsonSubTypes.Type(AssistantValue.class), + @JsonSubTypes.Type(SystemValue.class), + @JsonSubTypes.Type(ToolValue.class) + }) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } + + @JsonTypeName("user") + private static final class UserValue implements Value { + @JsonUnwrapped + private UserMessage value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private UserValue() {} + + private UserValue(UserMessage value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitUser(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof UserValue && equalTo((UserValue) other); + } + + private boolean equalTo(UserValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "ChatMessage2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("assistant") + private static final class AssistantValue implements Value { + @JsonUnwrapped + private AssistantMessage value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private AssistantValue() {} + + private AssistantValue(AssistantMessage value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitAssistant(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof AssistantValue && equalTo((AssistantValue) other); + } + + private boolean equalTo(AssistantValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "ChatMessage2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("system") + private static final class SystemValue implements Value { + @JsonUnwrapped + private SystemMessage value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private SystemValue() {} + + private SystemValue(SystemMessage value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitSystem(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof SystemValue && equalTo((SystemValue) other); + } + + private boolean equalTo(SystemValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "ChatMessage2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("tool") + private static final class ToolValue implements Value { + @JsonUnwrapped + private ToolMessage2 value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ToolValue() {} + + private ToolValue(ToolMessage2 value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitTool(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolValue && equalTo((ToolValue) other); + } + + private boolean equalTo(ToolValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "ChatMessage2{" + "value: " + value + "}"; + } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); + } + + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @java.lang.Override + public String toString() { + return "ChatMessage2{" + "type: " + type + ", value: " + value + "}"; + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatMessageEndEvent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatMessageEndEvent.java new file mode 100644 index 0000000..eff4da6 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatMessageEndEvent.java @@ -0,0 +1,118 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatMessageEndEvent.Builder.class) +public final class ChatMessageEndEvent implements IChatStreamEventType { + private final Optional id; + + private final Optional delta; + + private final Map additionalProperties; + + private ChatMessageEndEvent( + Optional id, Optional delta, Map additionalProperties) { + this.id = id; + this.delta = delta; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("id") + public Optional getId() { + return id; + } + + @JsonProperty("delta") + public Optional getDelta() { + return delta; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatMessageEndEvent && equalTo((ChatMessageEndEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatMessageEndEvent other) { + return id.equals(other.id) && delta.equals(other.delta); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.id, this.delta); + } + + @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 Optional id = Optional.empty(); + + private Optional delta = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatMessageEndEvent other) { + id(other.getId()); + delta(other.getDelta()); + return this; + } + + @JsonSetter(value = "id", nulls = Nulls.SKIP) + public Builder id(Optional id) { + this.id = id; + return this; + } + + public Builder id(String id) { + this.id = Optional.of(id); + return this; + } + + @JsonSetter(value = "delta", nulls = Nulls.SKIP) + public Builder delta(Optional delta) { + this.delta = delta; + return this; + } + + public Builder delta(ChatMessageEndEventDelta delta) { + this.delta = Optional.of(delta); + return this; + } + + public ChatMessageEndEvent build() { + return new ChatMessageEndEvent(id, delta, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatMessageEndEventDelta.java b/src/main/java/com/cohere/api/resources/v2/types/ChatMessageEndEventDelta.java new file mode 100644 index 0000000..afb67f5 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatMessageEndEventDelta.java @@ -0,0 +1,118 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatMessageEndEventDelta.Builder.class) +public final class ChatMessageEndEventDelta { + private final Optional finishReason; + + private final Optional usage; + + private final Map additionalProperties; + + private ChatMessageEndEventDelta( + Optional finishReason, Optional usage, Map additionalProperties) { + this.finishReason = finishReason; + this.usage = usage; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("finish_reason") + public Optional getFinishReason() { + return finishReason; + } + + @JsonProperty("usage") + public Optional getUsage() { + return usage; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatMessageEndEventDelta && equalTo((ChatMessageEndEventDelta) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatMessageEndEventDelta other) { + return finishReason.equals(other.finishReason) && usage.equals(other.usage); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.finishReason, this.usage); + } + + @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 Optional finishReason = Optional.empty(); + + private Optional usage = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatMessageEndEventDelta other) { + finishReason(other.getFinishReason()); + usage(other.getUsage()); + return this; + } + + @JsonSetter(value = "finish_reason", nulls = Nulls.SKIP) + public Builder finishReason(Optional finishReason) { + this.finishReason = finishReason; + return this; + } + + public Builder finishReason(ChatFinishReason finishReason) { + this.finishReason = Optional.of(finishReason); + return this; + } + + @JsonSetter(value = "usage", nulls = Nulls.SKIP) + public Builder usage(Optional usage) { + this.usage = usage; + return this; + } + + public Builder usage(Usage usage) { + this.usage = Optional.of(usage); + return this; + } + + public ChatMessageEndEventDelta build() { + return new ChatMessageEndEventDelta(finishReason, usage, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEvent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEvent.java new file mode 100644 index 0000000..c28bee2 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEvent.java @@ -0,0 +1,121 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatMessageStartEvent.Builder.class) +public final class ChatMessageStartEvent implements IChatStreamEventType { + private final Optional id; + + private final Optional delta; + + private final Map additionalProperties; + + private ChatMessageStartEvent( + Optional id, Optional delta, Map additionalProperties) { + this.id = id; + this.delta = delta; + this.additionalProperties = additionalProperties; + } + + /** + * @return Unique identifier for the generated reply. + */ + @JsonProperty("id") + public Optional getId() { + return id; + } + + @JsonProperty("delta") + public Optional getDelta() { + return delta; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatMessageStartEvent && equalTo((ChatMessageStartEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatMessageStartEvent other) { + return id.equals(other.id) && delta.equals(other.delta); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.id, this.delta); + } + + @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 Optional id = Optional.empty(); + + private Optional delta = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatMessageStartEvent other) { + id(other.getId()); + delta(other.getDelta()); + return this; + } + + @JsonSetter(value = "id", nulls = Nulls.SKIP) + public Builder id(Optional id) { + this.id = id; + return this; + } + + public Builder id(String id) { + this.id = Optional.of(id); + return this; + } + + @JsonSetter(value = "delta", nulls = Nulls.SKIP) + public Builder delta(Optional delta) { + this.delta = delta; + return this; + } + + public Builder delta(ChatMessageStartEventDelta delta) { + this.delta = Optional.of(delta); + return this; + } + + public ChatMessageStartEvent build() { + return new ChatMessageStartEvent(id, delta, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEventDelta.java b/src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEventDelta.java new file mode 100644 index 0000000..ea37c42 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEventDelta.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatMessageStartEventDelta.Builder.class) +public final class ChatMessageStartEventDelta { + private final Optional message; + + private final Map additionalProperties; + + private ChatMessageStartEventDelta( + Optional message, Map additionalProperties) { + this.message = message; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("message") + public Optional getMessage() { + return message; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatMessageStartEventDelta && equalTo((ChatMessageStartEventDelta) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatMessageStartEventDelta other) { + return message.equals(other.message); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.message); + } + + @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 Optional message = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatMessageStartEventDelta other) { + message(other.getMessage()); + return this; + } + + @JsonSetter(value = "message", nulls = Nulls.SKIP) + public Builder message(Optional message) { + this.message = message; + return this; + } + + public Builder message(ChatMessageStartEventDeltaMessage message) { + this.message = Optional.of(message); + return this; + } + + public ChatMessageStartEventDelta build() { + return new ChatMessageStartEventDelta(message, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEventDeltaMessage.java b/src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEventDeltaMessage.java new file mode 100644 index 0000000..e5edaa5 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatMessageStartEventDeltaMessage.java @@ -0,0 +1,98 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatMessageStartEventDeltaMessage.Builder.class) +public final class ChatMessageStartEventDeltaMessage { + private final Optional role; + + private final Map additionalProperties; + + private ChatMessageStartEventDeltaMessage(Optional role, Map additionalProperties) { + this.role = role; + this.additionalProperties = additionalProperties; + } + + /** + * @return The role of the message. + */ + @JsonProperty("role") + public Optional getRole() { + return role; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatMessageStartEventDeltaMessage && equalTo((ChatMessageStartEventDeltaMessage) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatMessageStartEventDeltaMessage other) { + return role.equals(other.role); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.role); + } + + @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 Optional role = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatMessageStartEventDeltaMessage other) { + role(other.getRole()); + return this; + } + + @JsonSetter(value = "role", nulls = Nulls.SKIP) + public Builder role(Optional role) { + this.role = role; + return this; + } + + public Builder role(String role) { + this.role = Optional.of(role); + return this; + } + + public ChatMessageStartEventDeltaMessage build() { + return new ChatMessageStartEventDeltaMessage(role, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatStreamEventType.java b/src/main/java/com/cohere/api/resources/v2/types/ChatStreamEventType.java new file mode 100644 index 0000000..c968ef7 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatStreamEventType.java @@ -0,0 +1,59 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatStreamEventType.Builder.class) +public final class ChatStreamEventType implements IChatStreamEventType { + private final Map additionalProperties; + + private ChatStreamEventType(Map additionalProperties) { + this.additionalProperties = additionalProperties; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatStreamEventType; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @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 { + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatStreamEventType other) { + return this; + } + + public ChatStreamEventType build() { + return new ChatStreamEventType(additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEvent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEvent.java new file mode 100644 index 0000000..35c0d89 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEvent.java @@ -0,0 +1,120 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolCallDeltaEvent.Builder.class) +public final class ChatToolCallDeltaEvent implements IChatStreamEventType { + private final Optional index; + + private final Optional delta; + + private final Map additionalProperties; + + private ChatToolCallDeltaEvent( + Optional index, + Optional delta, + Map additionalProperties) { + this.index = index; + this.delta = delta; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("index") + public Optional getIndex() { + return index; + } + + @JsonProperty("delta") + public Optional getDelta() { + return delta; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolCallDeltaEvent && equalTo((ChatToolCallDeltaEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolCallDeltaEvent other) { + return index.equals(other.index) && delta.equals(other.delta); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.index, this.delta); + } + + @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 Optional index = Optional.empty(); + + private Optional delta = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolCallDeltaEvent other) { + index(other.getIndex()); + delta(other.getDelta()); + return this; + } + + @JsonSetter(value = "index", nulls = Nulls.SKIP) + public Builder index(Optional index) { + this.index = index; + return this; + } + + public Builder index(Integer index) { + this.index = Optional.of(index); + return this; + } + + @JsonSetter(value = "delta", nulls = Nulls.SKIP) + public Builder delta(Optional delta) { + this.delta = delta; + return this; + } + + public Builder delta(ChatToolCallDeltaEventDelta delta) { + this.delta = Optional.of(delta); + return this; + } + + public ChatToolCallDeltaEvent build() { + return new ChatToolCallDeltaEvent(index, delta, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDelta.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDelta.java new file mode 100644 index 0000000..2608e7d --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDelta.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolCallDeltaEventDelta.Builder.class) +public final class ChatToolCallDeltaEventDelta { + private final Optional toolCall; + + private final Map additionalProperties; + + private ChatToolCallDeltaEventDelta( + Optional toolCall, Map additionalProperties) { + this.toolCall = toolCall; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("tool_call") + public Optional getToolCall() { + return toolCall; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolCallDeltaEventDelta && equalTo((ChatToolCallDeltaEventDelta) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolCallDeltaEventDelta other) { + return toolCall.equals(other.toolCall); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.toolCall); + } + + @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 Optional toolCall = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolCallDeltaEventDelta other) { + toolCall(other.getToolCall()); + return this; + } + + @JsonSetter(value = "tool_call", nulls = Nulls.SKIP) + public Builder toolCall(Optional toolCall) { + this.toolCall = toolCall; + return this; + } + + public Builder toolCall(ChatToolCallDeltaEventDeltaToolCall toolCall) { + this.toolCall = Optional.of(toolCall); + return this; + } + + public ChatToolCallDeltaEventDelta build() { + return new ChatToolCallDeltaEventDelta(toolCall, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDeltaToolCall.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDeltaToolCall.java new file mode 100644 index 0000000..6883da7 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDeltaToolCall.java @@ -0,0 +1,97 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolCallDeltaEventDeltaToolCall.Builder.class) +public final class ChatToolCallDeltaEventDeltaToolCall { + private final Optional function; + + private final Map additionalProperties; + + private ChatToolCallDeltaEventDeltaToolCall( + Optional function, Map additionalProperties) { + this.function = function; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("function") + public Optional getFunction() { + return function; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolCallDeltaEventDeltaToolCall + && equalTo((ChatToolCallDeltaEventDeltaToolCall) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolCallDeltaEventDeltaToolCall other) { + return function.equals(other.function); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.function); + } + + @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 Optional function = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolCallDeltaEventDeltaToolCall other) { + function(other.getFunction()); + return this; + } + + @JsonSetter(value = "function", nulls = Nulls.SKIP) + public Builder function(Optional function) { + this.function = function; + return this; + } + + public Builder function(ChatToolCallDeltaEventDeltaToolCallFunction function) { + this.function = Optional.of(function); + return this; + } + + public ChatToolCallDeltaEventDeltaToolCall build() { + return new ChatToolCallDeltaEventDeltaToolCall(function, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDeltaToolCallFunction.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDeltaToolCallFunction.java new file mode 100644 index 0000000..66c0aa2 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallDeltaEventDeltaToolCallFunction.java @@ -0,0 +1,97 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolCallDeltaEventDeltaToolCallFunction.Builder.class) +public final class ChatToolCallDeltaEventDeltaToolCallFunction { + private final Optional arguments; + + private final Map additionalProperties; + + private ChatToolCallDeltaEventDeltaToolCallFunction( + Optional arguments, Map additionalProperties) { + this.arguments = arguments; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("arguments") + public Optional getArguments() { + return arguments; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolCallDeltaEventDeltaToolCallFunction + && equalTo((ChatToolCallDeltaEventDeltaToolCallFunction) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolCallDeltaEventDeltaToolCallFunction other) { + return arguments.equals(other.arguments); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.arguments); + } + + @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 Optional arguments = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolCallDeltaEventDeltaToolCallFunction other) { + arguments(other.getArguments()); + return this; + } + + @JsonSetter(value = "arguments", nulls = Nulls.SKIP) + public Builder arguments(Optional arguments) { + this.arguments = arguments; + return this; + } + + public Builder arguments(String arguments) { + this.arguments = Optional.of(arguments); + return this; + } + + public ChatToolCallDeltaEventDeltaToolCallFunction build() { + return new ChatToolCallDeltaEventDeltaToolCallFunction(arguments, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallEndEvent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallEndEvent.java new file mode 100644 index 0000000..9d2c60e --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallEndEvent.java @@ -0,0 +1,95 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolCallEndEvent.Builder.class) +public final class ChatToolCallEndEvent implements IChatStreamEventType { + private final Optional index; + + private final Map additionalProperties; + + private ChatToolCallEndEvent(Optional index, Map additionalProperties) { + this.index = index; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("index") + public Optional getIndex() { + return index; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolCallEndEvent && equalTo((ChatToolCallEndEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolCallEndEvent other) { + return index.equals(other.index); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.index); + } + + @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 Optional index = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolCallEndEvent other) { + index(other.getIndex()); + return this; + } + + @JsonSetter(value = "index", nulls = Nulls.SKIP) + public Builder index(Optional index) { + this.index = index; + return this; + } + + public Builder index(Integer index) { + this.index = Optional.of(index); + return this; + } + + public ChatToolCallEndEvent build() { + return new ChatToolCallEndEvent(index, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEvent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEvent.java new file mode 100644 index 0000000..819fb1f --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEvent.java @@ -0,0 +1,120 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolCallStartEvent.Builder.class) +public final class ChatToolCallStartEvent implements IChatStreamEventType { + private final Optional index; + + private final Optional delta; + + private final Map additionalProperties; + + private ChatToolCallStartEvent( + Optional index, + Optional delta, + Map additionalProperties) { + this.index = index; + this.delta = delta; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("index") + public Optional getIndex() { + return index; + } + + @JsonProperty("delta") + public Optional getDelta() { + return delta; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolCallStartEvent && equalTo((ChatToolCallStartEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolCallStartEvent other) { + return index.equals(other.index) && delta.equals(other.delta); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.index, this.delta); + } + + @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 Optional index = Optional.empty(); + + private Optional delta = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolCallStartEvent other) { + index(other.getIndex()); + delta(other.getDelta()); + return this; + } + + @JsonSetter(value = "index", nulls = Nulls.SKIP) + public Builder index(Optional index) { + this.index = index; + return this; + } + + public Builder index(Integer index) { + this.index = Optional.of(index); + return this; + } + + @JsonSetter(value = "delta", nulls = Nulls.SKIP) + public Builder delta(Optional delta) { + this.delta = delta; + return this; + } + + public Builder delta(ChatToolCallStartEventDelta delta) { + this.delta = Optional.of(delta); + return this; + } + + public ChatToolCallStartEvent build() { + return new ChatToolCallStartEvent(index, delta, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDelta.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDelta.java new file mode 100644 index 0000000..e700d6d --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDelta.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolCallStartEventDelta.Builder.class) +public final class ChatToolCallStartEventDelta { + private final Optional toolCall; + + private final Map additionalProperties; + + private ChatToolCallStartEventDelta( + Optional toolCall, Map additionalProperties) { + this.toolCall = toolCall; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("tool_call") + public Optional getToolCall() { + return toolCall; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolCallStartEventDelta && equalTo((ChatToolCallStartEventDelta) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolCallStartEventDelta other) { + return toolCall.equals(other.toolCall); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.toolCall); + } + + @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 Optional toolCall = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolCallStartEventDelta other) { + toolCall(other.getToolCall()); + return this; + } + + @JsonSetter(value = "tool_call", nulls = Nulls.SKIP) + public Builder toolCall(Optional toolCall) { + this.toolCall = toolCall; + return this; + } + + public Builder toolCall(ChatToolCallStartEventDeltaToolCall toolCall) { + this.toolCall = Optional.of(toolCall); + return this; + } + + public ChatToolCallStartEventDelta build() { + return new ChatToolCallStartEventDelta(toolCall, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDeltaToolCall.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDeltaToolCall.java new file mode 100644 index 0000000..6b2c73c --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDeltaToolCall.java @@ -0,0 +1,144 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolCallStartEventDeltaToolCall.Builder.class) +public final class ChatToolCallStartEventDeltaToolCall { + private final Optional id; + + private final Optional type; + + private final Optional function; + + private final Map additionalProperties; + + private ChatToolCallStartEventDeltaToolCall( + Optional id, + Optional type, + Optional function, + Map additionalProperties) { + this.id = id; + this.type = type; + this.function = function; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("id") + public Optional getId() { + return id; + } + + @JsonProperty("type") + public Optional getType() { + return type; + } + + @JsonProperty("function") + public Optional getFunction() { + return function; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolCallStartEventDeltaToolCall + && equalTo((ChatToolCallStartEventDeltaToolCall) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolCallStartEventDeltaToolCall other) { + return id.equals(other.id) && type.equals(other.type) && function.equals(other.function); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.id, this.type, this.function); + } + + @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 Optional id = Optional.empty(); + + private Optional type = Optional.empty(); + + private Optional function = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolCallStartEventDeltaToolCall other) { + id(other.getId()); + type(other.getType()); + function(other.getFunction()); + return this; + } + + @JsonSetter(value = "id", nulls = Nulls.SKIP) + public Builder id(Optional id) { + this.id = id; + return this; + } + + public Builder id(String id) { + this.id = Optional.of(id); + return this; + } + + @JsonSetter(value = "type", nulls = Nulls.SKIP) + public Builder type(Optional type) { + this.type = type; + return this; + } + + public Builder type(String type) { + this.type = Optional.of(type); + return this; + } + + @JsonSetter(value = "function", nulls = Nulls.SKIP) + public Builder function(Optional function) { + this.function = function; + return this; + } + + public Builder function(ChatToolCallStartEventDeltaToolCallFunction function) { + this.function = Optional.of(function); + return this; + } + + public ChatToolCallStartEventDeltaToolCall build() { + return new ChatToolCallStartEventDeltaToolCall(id, type, function, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDeltaToolCallFunction.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDeltaToolCallFunction.java new file mode 100644 index 0000000..b798b7b --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolCallStartEventDeltaToolCallFunction.java @@ -0,0 +1,119 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolCallStartEventDeltaToolCallFunction.Builder.class) +public final class ChatToolCallStartEventDeltaToolCallFunction { + private final Optional name; + + private final Optional arguments; + + private final Map additionalProperties; + + private ChatToolCallStartEventDeltaToolCallFunction( + Optional name, Optional arguments, Map additionalProperties) { + this.name = name; + this.arguments = arguments; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("name") + public Optional getName() { + return name; + } + + @JsonProperty("arguments") + public Optional getArguments() { + return arguments; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolCallStartEventDeltaToolCallFunction + && equalTo((ChatToolCallStartEventDeltaToolCallFunction) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolCallStartEventDeltaToolCallFunction other) { + return name.equals(other.name) && arguments.equals(other.arguments); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.name, this.arguments); + } + + @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 Optional name = Optional.empty(); + + private Optional arguments = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolCallStartEventDeltaToolCallFunction other) { + name(other.getName()); + arguments(other.getArguments()); + return this; + } + + @JsonSetter(value = "name", nulls = Nulls.SKIP) + public Builder name(Optional name) { + this.name = name; + return this; + } + + public Builder name(String name) { + this.name = Optional.of(name); + return this; + } + + @JsonSetter(value = "arguments", nulls = Nulls.SKIP) + public Builder arguments(Optional arguments) { + this.arguments = arguments; + return this; + } + + public Builder arguments(String arguments) { + this.arguments = Optional.of(arguments); + return this; + } + + public ChatToolCallStartEventDeltaToolCallFunction build() { + return new ChatToolCallStartEventDeltaToolCallFunction(name, arguments, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolPlanDeltaEvent.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolPlanDeltaEvent.java new file mode 100644 index 0000000..911701c --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolPlanDeltaEvent.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolPlanDeltaEvent.Builder.class) +public final class ChatToolPlanDeltaEvent implements IChatStreamEventType { + private final Optional delta; + + private final Map additionalProperties; + + private ChatToolPlanDeltaEvent( + Optional delta, Map additionalProperties) { + this.delta = delta; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("delta") + public Optional getDelta() { + return delta; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolPlanDeltaEvent && equalTo((ChatToolPlanDeltaEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolPlanDeltaEvent other) { + return delta.equals(other.delta); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.delta); + } + + @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 Optional delta = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolPlanDeltaEvent other) { + delta(other.getDelta()); + return this; + } + + @JsonSetter(value = "delta", nulls = Nulls.SKIP) + public Builder delta(Optional delta) { + this.delta = delta; + return this; + } + + public Builder delta(ChatToolPlanDeltaEventDelta delta) { + this.delta = Optional.of(delta); + return this; + } + + public ChatToolPlanDeltaEvent build() { + return new ChatToolPlanDeltaEvent(delta, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ChatToolPlanDeltaEventDelta.java b/src/main/java/com/cohere/api/resources/v2/types/ChatToolPlanDeltaEventDelta.java new file mode 100644 index 0000000..45e8501 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ChatToolPlanDeltaEventDelta.java @@ -0,0 +1,95 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ChatToolPlanDeltaEventDelta.Builder.class) +public final class ChatToolPlanDeltaEventDelta { + private final Optional toolPlan; + + private final Map additionalProperties; + + private ChatToolPlanDeltaEventDelta(Optional toolPlan, Map additionalProperties) { + this.toolPlan = toolPlan; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("tool_plan") + public Optional getToolPlan() { + return toolPlan; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ChatToolPlanDeltaEventDelta && equalTo((ChatToolPlanDeltaEventDelta) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ChatToolPlanDeltaEventDelta other) { + return toolPlan.equals(other.toolPlan); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.toolPlan); + } + + @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 Optional toolPlan = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ChatToolPlanDeltaEventDelta other) { + toolPlan(other.getToolPlan()); + return this; + } + + @JsonSetter(value = "tool_plan", nulls = Nulls.SKIP) + public Builder toolPlan(Optional toolPlan) { + this.toolPlan = toolPlan; + return this; + } + + public Builder toolPlan(String toolPlan) { + this.toolPlan = Optional.of(toolPlan); + return this; + } + + public ChatToolPlanDeltaEventDelta build() { + return new ChatToolPlanDeltaEventDelta(toolPlan, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/Citation.java b/src/main/java/com/cohere/api/resources/v2/types/Citation.java new file mode 100644 index 0000000..c815f63 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/Citation.java @@ -0,0 +1,170 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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 = Citation.Builder.class) +public final class Citation { + private final Optional start; + + private final Optional end; + + private final Optional text; + + private final Optional> sources; + + private final Map additionalProperties; + + private Citation( + Optional start, + Optional end, + Optional text, + Optional> sources, + Map additionalProperties) { + this.start = start; + this.end = end; + this.text = text; + this.sources = sources; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("start") + public Optional getStart() { + return start; + } + + @JsonProperty("end") + public Optional getEnd() { + return end; + } + + @JsonProperty("text") + public Optional getText() { + return text; + } + + @JsonProperty("sources") + public Optional> getSources() { + return sources; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof Citation && equalTo((Citation) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(Citation other) { + return start.equals(other.start) + && end.equals(other.end) + && text.equals(other.text) + && sources.equals(other.sources); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.start, this.end, this.text, this.sources); + } + + @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 Optional start = Optional.empty(); + + private Optional end = Optional.empty(); + + private Optional text = Optional.empty(); + + private Optional> sources = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(Citation other) { + start(other.getStart()); + end(other.getEnd()); + text(other.getText()); + sources(other.getSources()); + return this; + } + + @JsonSetter(value = "start", nulls = Nulls.SKIP) + public Builder start(Optional start) { + this.start = start; + return this; + } + + public Builder start(Integer start) { + this.start = Optional.of(start); + return this; + } + + @JsonSetter(value = "end", nulls = Nulls.SKIP) + public Builder end(Optional end) { + this.end = end; + return this; + } + + public Builder end(Integer end) { + this.end = Optional.of(end); + return this; + } + + @JsonSetter(value = "text", nulls = Nulls.SKIP) + public Builder text(Optional text) { + this.text = text; + return this; + } + + public Builder text(String text) { + this.text = Optional.of(text); + return this; + } + + @JsonSetter(value = "sources", nulls = Nulls.SKIP) + public Builder sources(Optional> sources) { + this.sources = sources; + return this; + } + + public Builder sources(List sources) { + this.sources = Optional.of(sources); + return this; + } + + public Citation build() { + return new Citation(start, end, text, sources, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/CitationEndEvent.java b/src/main/java/com/cohere/api/resources/v2/types/CitationEndEvent.java new file mode 100644 index 0000000..f880263 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/CitationEndEvent.java @@ -0,0 +1,95 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = CitationEndEvent.Builder.class) +public final class CitationEndEvent implements IChatStreamEventType { + private final Optional index; + + private final Map additionalProperties; + + private CitationEndEvent(Optional index, Map additionalProperties) { + this.index = index; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("index") + public Optional getIndex() { + return index; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof CitationEndEvent && equalTo((CitationEndEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(CitationEndEvent other) { + return index.equals(other.index); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.index); + } + + @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 Optional index = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(CitationEndEvent other) { + index(other.getIndex()); + return this; + } + + @JsonSetter(value = "index", nulls = Nulls.SKIP) + public Builder index(Optional index) { + this.index = index; + return this; + } + + public Builder index(Integer index) { + this.index = Optional.of(index); + return this; + } + + public CitationEndEvent build() { + return new CitationEndEvent(index, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/CitationOptions.java b/src/main/java/com/cohere/api/resources/v2/types/CitationOptions.java new file mode 100644 index 0000000..dccae69 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/CitationOptions.java @@ -0,0 +1,99 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = CitationOptions.Builder.class) +public final class CitationOptions { + private final Optional mode; + + private final Map additionalProperties; + + private CitationOptions(Optional mode, Map additionalProperties) { + this.mode = mode; + this.additionalProperties = additionalProperties; + } + + /** + * @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, "fast" results or no results. + */ + @JsonProperty("mode") + public Optional getMode() { + return mode; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof CitationOptions && equalTo((CitationOptions) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(CitationOptions other) { + return mode.equals(other.mode); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.mode); + } + + @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 Optional mode = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(CitationOptions other) { + mode(other.getMode()); + return this; + } + + @JsonSetter(value = "mode", nulls = Nulls.SKIP) + public Builder mode(Optional mode) { + this.mode = mode; + return this; + } + + public Builder mode(CitationOptionsMode mode) { + this.mode = Optional.of(mode); + return this; + } + + public CitationOptions build() { + return new CitationOptions(mode, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/CitationOptionsMode.java b/src/main/java/com/cohere/api/resources/v2/types/CitationOptionsMode.java new file mode 100644 index 0000000..4c07e16 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/CitationOptionsMode.java @@ -0,0 +1,26 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum CitationOptionsMode { + FAST("FAST"), + + ACCURATE("ACCURATE"), + + OFF("OFF"); + + private final String value; + + CitationOptionsMode(String value) { + this.value = value; + } + + @JsonValue + @java.lang.Override + public String toString() { + return this.value; + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/CitationStartEvent.java b/src/main/java/com/cohere/api/resources/v2/types/CitationStartEvent.java new file mode 100644 index 0000000..435897f --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/CitationStartEvent.java @@ -0,0 +1,120 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = CitationStartEvent.Builder.class) +public final class CitationStartEvent implements IChatStreamEventType { + private final Optional index; + + private final Optional delta; + + private final Map additionalProperties; + + private CitationStartEvent( + Optional index, + Optional delta, + Map additionalProperties) { + this.index = index; + this.delta = delta; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("index") + public Optional getIndex() { + return index; + } + + @JsonProperty("delta") + public Optional getDelta() { + return delta; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof CitationStartEvent && equalTo((CitationStartEvent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(CitationStartEvent other) { + return index.equals(other.index) && delta.equals(other.delta); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.index, this.delta); + } + + @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 Optional index = Optional.empty(); + + private Optional delta = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(CitationStartEvent other) { + index(other.getIndex()); + delta(other.getDelta()); + return this; + } + + @JsonSetter(value = "index", nulls = Nulls.SKIP) + public Builder index(Optional index) { + this.index = index; + return this; + } + + public Builder index(Integer index) { + this.index = Optional.of(index); + return this; + } + + @JsonSetter(value = "delta", nulls = Nulls.SKIP) + public Builder delta(Optional delta) { + this.delta = delta; + return this; + } + + public Builder delta(CitationStartEventDelta delta) { + this.delta = Optional.of(delta); + return this; + } + + public CitationStartEvent build() { + return new CitationStartEvent(index, delta, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/CitationStartEventDelta.java b/src/main/java/com/cohere/api/resources/v2/types/CitationStartEventDelta.java new file mode 100644 index 0000000..a33ba0b --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/CitationStartEventDelta.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = CitationStartEventDelta.Builder.class) +public final class CitationStartEventDelta { + private final Optional message; + + private final Map additionalProperties; + + private CitationStartEventDelta( + Optional message, Map additionalProperties) { + this.message = message; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("message") + public Optional getMessage() { + return message; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof CitationStartEventDelta && equalTo((CitationStartEventDelta) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(CitationStartEventDelta other) { + return message.equals(other.message); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.message); + } + + @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 Optional message = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(CitationStartEventDelta other) { + message(other.getMessage()); + return this; + } + + @JsonSetter(value = "message", nulls = Nulls.SKIP) + public Builder message(Optional message) { + this.message = message; + return this; + } + + public Builder message(CitationStartEventDeltaMessage message) { + this.message = Optional.of(message); + return this; + } + + public CitationStartEventDelta build() { + return new CitationStartEventDelta(message, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/CitationStartEventDeltaMessage.java b/src/main/java/com/cohere/api/resources/v2/types/CitationStartEventDeltaMessage.java new file mode 100644 index 0000000..8f048a0 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/CitationStartEventDeltaMessage.java @@ -0,0 +1,95 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = CitationStartEventDeltaMessage.Builder.class) +public final class CitationStartEventDeltaMessage { + private final Optional citations; + + private final Map additionalProperties; + + private CitationStartEventDeltaMessage(Optional citations, Map additionalProperties) { + this.citations = citations; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("citations") + public Optional getCitations() { + return citations; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof CitationStartEventDeltaMessage && equalTo((CitationStartEventDeltaMessage) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(CitationStartEventDeltaMessage other) { + return citations.equals(other.citations); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.citations); + } + + @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 Optional citations = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(CitationStartEventDeltaMessage other) { + citations(other.getCitations()); + return this; + } + + @JsonSetter(value = "citations", nulls = Nulls.SKIP) + public Builder citations(Optional citations) { + this.citations = citations; + return this; + } + + public Builder citations(Citation citations) { + this.citations = Optional.of(citations); + return this; + } + + public CitationStartEventDeltaMessage build() { + return new CitationStartEventDeltaMessage(citations, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/Content.java b/src/main/java/com/cohere/api/resources/v2/types/Content.java new file mode 100644 index 0000000..88111f7 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/Content.java @@ -0,0 +1,145 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Objects; +import java.util.Optional; + +public final class Content { + private final Value value; + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private Content(Value value) { + this.value = value; + } + + public T visit(Visitor visitor) { + return value.visit(visitor); + } + + public static Content text(TextContent value) { + return new Content(new TextValue(value)); + } + + public boolean isText() { + return value instanceof TextValue; + } + + public boolean _isUnknown() { + return value instanceof _UnknownValue; + } + + public Optional getText() { + if (isText()) { + return Optional.of(((TextValue) value).value); + } + return Optional.empty(); + } + + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); + } + + @JsonValue + private Value getValue() { + return this.value; + } + + public interface Visitor { + T visitText(TextContent text); + + T _visitUnknown(Object unknownType); + } + + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = _UnknownValue.class) + @JsonSubTypes(@JsonSubTypes.Type(TextValue.class)) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } + + @JsonTypeName("text") + private static final class TextValue implements Value { + @JsonUnwrapped + private TextContent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private TextValue() {} + + private TextValue(TextContent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitText(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof TextValue && equalTo((TextValue) other); + } + + private boolean equalTo(TextValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "Content{" + "value: " + value + "}"; + } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); + } + + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @java.lang.Override + public String toString() { + return "Content{" + "type: " + type + ", value: " + value + "}"; + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/Document.java b/src/main/java/com/cohere/api/resources/v2/types/Document.java new file mode 100644 index 0000000..2f3b415 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/Document.java @@ -0,0 +1,130 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.LinkedHashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = Document.Builder.class) +public final class Document { + private final Map data; + + private final Optional id; + + private final Map additionalProperties; + + private Document(Map data, Optional id, Map additionalProperties) { + this.data = data; + this.id = id; + this.additionalProperties = additionalProperties; + } + + /** + * @return A relevant documents that the model can cite to generate a more accurate reply. Each document is a string-string dictionary. + */ + @JsonProperty("data") + public Map getData() { + return data; + } + + /** + * @return Unique identifier for this document which will be referenced in citations. If not provided an ID will be automatically generated + */ + @JsonProperty("id") + public Optional getId() { + return id; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof Document && equalTo((Document) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(Document other) { + return data.equals(other.data) && id.equals(other.id); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.data, this.id); + } + + @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 Map data = new LinkedHashMap<>(); + + private Optional id = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(Document other) { + data(other.getData()); + id(other.getId()); + return this; + } + + @JsonSetter(value = "data", nulls = Nulls.SKIP) + public Builder data(Map data) { + this.data.clear(); + this.data.putAll(data); + return this; + } + + public Builder putAllData(Map data) { + this.data.putAll(data); + return this; + } + + public Builder data(String key, String value) { + this.data.put(key, value); + return this; + } + + @JsonSetter(value = "id", nulls = Nulls.SKIP) + public Builder id(Optional id) { + this.id = id; + return this; + } + + public Builder id(String id) { + this.id = Optional.of(id); + return this; + } + + public Document build() { + return new Document(data, id, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/DocumentContent.java b/src/main/java/com/cohere/api/resources/v2/types/DocumentContent.java new file mode 100644 index 0000000..2f1d713 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/DocumentContent.java @@ -0,0 +1,101 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = DocumentContent.Builder.class) +public final class DocumentContent { + private final Document document; + + private final Map additionalProperties; + + private DocumentContent(Document document, Map additionalProperties) { + this.document = document; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("document") + public Document getDocument() { + return document; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof DocumentContent && equalTo((DocumentContent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(DocumentContent other) { + return document.equals(other.document); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.document); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static DocumentStage builder() { + return new Builder(); + } + + public interface DocumentStage { + _FinalStage document(Document document); + + Builder from(DocumentContent other); + } + + public interface _FinalStage { + DocumentContent build(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements DocumentStage, _FinalStage { + private Document document; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(DocumentContent other) { + document(other.getDocument()); + return this; + } + + @java.lang.Override + @JsonSetter("document") + public _FinalStage document(Document document) { + this.document = document; + return this; + } + + @java.lang.Override + public DocumentContent build() { + return new DocumentContent(document, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/DocumentSource.java b/src/main/java/com/cohere/api/resources/v2/types/DocumentSource.java new file mode 100644 index 0000000..02c7451 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/DocumentSource.java @@ -0,0 +1,121 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = DocumentSource.Builder.class) +public final class DocumentSource { + private final Optional id; + + private final Optional> document; + + private final Map additionalProperties; + + private DocumentSource( + Optional id, Optional> document, Map additionalProperties) { + this.id = id; + this.document = document; + this.additionalProperties = additionalProperties; + } + + /** + * @return The unique identifier of the document + */ + @JsonProperty("id") + public Optional getId() { + return id; + } + + @JsonProperty("document") + public Optional> getDocument() { + return document; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof DocumentSource && equalTo((DocumentSource) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(DocumentSource other) { + return id.equals(other.id) && document.equals(other.document); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.id, this.document); + } + + @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 Optional id = Optional.empty(); + + private Optional> document = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(DocumentSource other) { + id(other.getId()); + document(other.getDocument()); + return this; + } + + @JsonSetter(value = "id", nulls = Nulls.SKIP) + public Builder id(Optional id) { + this.id = id; + return this; + } + + public Builder id(String id) { + this.id = Optional.of(id); + return this; + } + + @JsonSetter(value = "document", nulls = Nulls.SKIP) + public Builder document(Optional> document) { + this.document = document; + return this; + } + + public Builder document(Map document) { + this.document = Optional.of(document); + return this; + } + + public DocumentSource build() { + return new DocumentSource(id, document, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/IChatStreamEventType.java b/src/main/java/com/cohere/api/resources/v2/types/IChatStreamEventType.java new file mode 100644 index 0000000..2630fbf --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/IChatStreamEventType.java @@ -0,0 +1,6 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +public interface IChatStreamEventType {} diff --git a/src/main/java/com/cohere/api/resources/v2/types/Images.java b/src/main/java/com/cohere/api/resources/v2/types/Images.java new file mode 100644 index 0000000..7edab35 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/Images.java @@ -0,0 +1,239 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +import com.cohere.api.types.EmbeddingType; +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 = Images.Builder.class) +public final class Images { + private final List images; + + private final String model; + + private final Optional> embeddingTypes; + + private final Map additionalProperties; + + private Images( + List images, + String model, + Optional> embeddingTypes, + Map additionalProperties) { + this.images = images; + this.model = model; + this.embeddingTypes = embeddingTypes; + this.additionalProperties = additionalProperties; + } + + /** + * @return An array of image data URIs for the model to embed. Maximum number of images per call is 1. + * The image must be a valid data URI. The image must be in either image/jpeg or image/png format and has a maximum size of 5MB. + */ + @JsonProperty("images") + public List getImages() { + return images; + } + + /** + * @return Defaults to embed-english-v2.0 + * The identifier of the model. Smaller "light" models are faster, while larger models will perform better. Custom models can also be supplied with their full ID. + * Available models and corresponding embedding dimensions: + *
    + *
  • embed-english-v3.0 1024
  • + *
  • embed-multilingual-v3.0 1024
  • + *
  • embed-english-light-v3.0 384
  • + *
  • embed-multilingual-light-v3.0 384
  • + *
  • embed-english-v2.0 4096
  • + *
  • embed-english-light-v2.0 1024
  • + *
  • embed-multilingual-v2.0 768
  • + *
+ */ + @JsonProperty("model") + public String getModel() { + return model; + } + + /** + * @return Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types. + *
    + *
  • "float": Use this when you want to get back the default float embeddings. Valid for all models.
  • + *
  • "int8": Use this when you want to get back signed int8 embeddings. Valid for only v3 models.
  • + *
  • "uint8": Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models.
  • + *
  • "binary": Use this when you want to get back signed binary embeddings. Valid for only v3 models.
  • + *
  • "ubinary": Use this when you want to get back unsigned binary embeddings. Valid for only v3 models.
  • + *
+ */ + @JsonProperty("embedding_types") + public Optional> getEmbeddingTypes() { + return embeddingTypes; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof Images && equalTo((Images) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(Images other) { + return images.equals(other.images) && model.equals(other.model) && embeddingTypes.equals(other.embeddingTypes); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.images, this.model, this.embeddingTypes); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static ModelStage builder() { + return new Builder(); + } + + public interface ModelStage { + _FinalStage model(String model); + + Builder from(Images other); + } + + public interface _FinalStage { + Images build(); + + _FinalStage images(List images); + + _FinalStage addImages(String images); + + _FinalStage addAllImages(List images); + + _FinalStage embeddingTypes(Optional> embeddingTypes); + + _FinalStage embeddingTypes(List embeddingTypes); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements ModelStage, _FinalStage { + private String model; + + private Optional> embeddingTypes = Optional.empty(); + + private List images = new ArrayList<>(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(Images other) { + images(other.getImages()); + model(other.getModel()); + embeddingTypes(other.getEmbeddingTypes()); + return this; + } + + /** + *

Defaults to embed-english-v2.0 + * The identifier of the model. Smaller "light" models are faster, while larger models will perform better. Custom models can also be supplied with their full ID. + * Available models and corresponding embedding dimensions:

+ *
    + *
  • embed-english-v3.0 1024
  • + *
  • embed-multilingual-v3.0 1024
  • + *
  • embed-english-light-v3.0 384
  • + *
  • embed-multilingual-light-v3.0 384
  • + *
  • embed-english-v2.0 4096
  • + *
  • embed-english-light-v2.0 1024
  • + *
  • embed-multilingual-v2.0 768
  • + *
+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("model") + public _FinalStage model(String model) { + this.model = model; + return this; + } + + /** + *

Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types.

+ *
    + *
  • "float": Use this when you want to get back the default float embeddings. Valid for all models.
  • + *
  • "int8": Use this when you want to get back signed int8 embeddings. Valid for only v3 models.
  • + *
  • "uint8": Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models.
  • + *
  • "binary": Use this when you want to get back signed binary embeddings. Valid for only v3 models.
  • + *
  • "ubinary": Use this when you want to get back unsigned binary embeddings. Valid for only v3 models.
  • + *
+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage embeddingTypes(List embeddingTypes) { + this.embeddingTypes = Optional.of(embeddingTypes); + return this; + } + + @java.lang.Override + @JsonSetter(value = "embedding_types", nulls = Nulls.SKIP) + public _FinalStage embeddingTypes(Optional> embeddingTypes) { + this.embeddingTypes = embeddingTypes; + return this; + } + + /** + *

An array of image data URIs for the model to embed. Maximum number of images per call is 1. + * The image must be a valid data URI. The image must be in either image/jpeg or image/png format and has a maximum size of 5MB.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage addAllImages(List images) { + this.images.addAll(images); + return this; + } + + /** + *

An array of image data URIs for the model to embed. Maximum number of images per call is 1. + * The image must be a valid data URI. The image must be in either image/jpeg or image/png format and has a maximum size of 5MB.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage addImages(String images) { + this.images.add(images); + return this; + } + + @java.lang.Override + @JsonSetter(value = "images", nulls = Nulls.SKIP) + public _FinalStage images(List images) { + this.images.clear(); + this.images.addAll(images); + return this; + } + + @java.lang.Override + public Images build() { + return new Images(images, model, embeddingTypes, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/JsonResponseFormat2.java b/src/main/java/com/cohere/api/resources/v2/types/JsonResponseFormat2.java new file mode 100644 index 0000000..eb9d163 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/JsonResponseFormat2.java @@ -0,0 +1,109 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = JsonResponseFormat2.Builder.class) +public final class JsonResponseFormat2 { + private final Optional> jsonSchema; + + private final Map additionalProperties; + + private JsonResponseFormat2(Optional> jsonSchema, Map additionalProperties) { + this.jsonSchema = jsonSchema; + this.additionalProperties = additionalProperties; + } + + /** + * @return [BETA] A JSON schema object that the output will adhere to. There are some restrictions we have on the schema, refer to our guide for more information. + * Example (required name and age object): + *
{
+     *   "type": "object",
+     *   "properties": {
+     *     "name": { "type": "string" },
+     *     "age": { "type": "integer" }
+     *   },
+     *   "required": ["name", "age"]
+     * }
+     * 
+ *

Note: This field must not be specified when the type is set to "text".

+ */ + @JsonProperty("json_schema") + public Optional> getJsonSchema() { + return jsonSchema; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof JsonResponseFormat2 && equalTo((JsonResponseFormat2) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(JsonResponseFormat2 other) { + return jsonSchema.equals(other.jsonSchema); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.jsonSchema); + } + + @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 Optional> jsonSchema = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(JsonResponseFormat2 other) { + jsonSchema(other.getJsonSchema()); + return this; + } + + @JsonSetter(value = "json_schema", nulls = Nulls.SKIP) + public Builder jsonSchema(Optional> jsonSchema) { + this.jsonSchema = jsonSchema; + return this; + } + + public Builder jsonSchema(Map jsonSchema) { + this.jsonSchema = Optional.of(jsonSchema); + return this; + } + + public JsonResponseFormat2 build() { + return new JsonResponseFormat2(jsonSchema, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/NonStreamedChatResponse2.java b/src/main/java/com/cohere/api/resources/v2/types/NonStreamedChatResponse2.java new file mode 100644 index 0000000..32930e8 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/NonStreamedChatResponse2.java @@ -0,0 +1,233 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = NonStreamedChatResponse2.Builder.class) +public final class NonStreamedChatResponse2 { + private final String id; + + private final ChatFinishReason finishReason; + + private final Optional prompt; + + private final Optional message; + + private final Optional usage; + + private final Map additionalProperties; + + private NonStreamedChatResponse2( + String id, + ChatFinishReason finishReason, + Optional prompt, + Optional message, + Optional usage, + Map additionalProperties) { + this.id = id; + this.finishReason = finishReason; + this.prompt = prompt; + this.message = message; + this.usage = usage; + this.additionalProperties = additionalProperties; + } + + /** + * @return Unique identifier for the generated reply. Useful for submitting feedback. + */ + @JsonProperty("id") + public String getId() { + return id; + } + + @JsonProperty("finish_reason") + public ChatFinishReason getFinishReason() { + return finishReason; + } + + /** + * @return The prompt that was used. Only present when return_prompt in the request is set to true. + */ + @JsonProperty("prompt") + public Optional getPrompt() { + return prompt; + } + + @JsonProperty("message") + public Optional getMessage() { + return message; + } + + @JsonProperty("usage") + public Optional getUsage() { + return usage; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof NonStreamedChatResponse2 && equalTo((NonStreamedChatResponse2) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(NonStreamedChatResponse2 other) { + return id.equals(other.id) + && finishReason.equals(other.finishReason) + && prompt.equals(other.prompt) + && message.equals(other.message) + && usage.equals(other.usage); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.id, this.finishReason, this.prompt, this.message, this.usage); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static IdStage builder() { + return new Builder(); + } + + public interface IdStage { + FinishReasonStage id(String id); + + Builder from(NonStreamedChatResponse2 other); + } + + public interface FinishReasonStage { + _FinalStage finishReason(ChatFinishReason finishReason); + } + + public interface _FinalStage { + NonStreamedChatResponse2 build(); + + _FinalStage prompt(Optional prompt); + + _FinalStage prompt(String prompt); + + _FinalStage message(Optional message); + + _FinalStage message(AssistantMessageResponse message); + + _FinalStage usage(Optional usage); + + _FinalStage usage(Usage usage); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements IdStage, FinishReasonStage, _FinalStage { + private String id; + + private ChatFinishReason finishReason; + + private Optional usage = Optional.empty(); + + private Optional message = Optional.empty(); + + private Optional prompt = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(NonStreamedChatResponse2 other) { + id(other.getId()); + finishReason(other.getFinishReason()); + prompt(other.getPrompt()); + message(other.getMessage()); + usage(other.getUsage()); + return this; + } + + /** + *

Unique identifier for the generated reply. Useful for submitting feedback.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("id") + public FinishReasonStage id(String id) { + this.id = id; + return this; + } + + @java.lang.Override + @JsonSetter("finish_reason") + public _FinalStage finishReason(ChatFinishReason finishReason) { + this.finishReason = finishReason; + return this; + } + + @java.lang.Override + public _FinalStage usage(Usage usage) { + this.usage = Optional.of(usage); + return this; + } + + @java.lang.Override + @JsonSetter(value = "usage", nulls = Nulls.SKIP) + public _FinalStage usage(Optional usage) { + this.usage = usage; + return this; + } + + @java.lang.Override + public _FinalStage message(AssistantMessageResponse message) { + this.message = Optional.of(message); + return this; + } + + @java.lang.Override + @JsonSetter(value = "message", nulls = Nulls.SKIP) + public _FinalStage message(Optional message) { + this.message = message; + return this; + } + + /** + *

The prompt that was used. Only present when return_prompt in the request is set to true.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage prompt(String prompt) { + this.prompt = Optional.of(prompt); + return this; + } + + @java.lang.Override + @JsonSetter(value = "prompt", nulls = Nulls.SKIP) + public _FinalStage prompt(Optional prompt) { + this.prompt = prompt; + return this; + } + + @java.lang.Override + public NonStreamedChatResponse2 build() { + return new NonStreamedChatResponse2(id, finishReason, prompt, message, usage, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ResponseFormat2.java b/src/main/java/com/cohere/api/resources/v2/types/ResponseFormat2.java new file mode 100644 index 0000000..95ed6e4 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ResponseFormat2.java @@ -0,0 +1,200 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Objects; +import java.util.Optional; + +public final class ResponseFormat2 { + private final Value value; + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private ResponseFormat2(Value value) { + this.value = value; + } + + public T visit(Visitor visitor) { + return value.visit(visitor); + } + + public static ResponseFormat2 text(TextResponseFormat2 value) { + return new ResponseFormat2(new TextValue(value)); + } + + public static ResponseFormat2 jsonObject(JsonResponseFormat2 value) { + return new ResponseFormat2(new JsonObjectValue(value)); + } + + public boolean isText() { + return value instanceof TextValue; + } + + public boolean isJsonObject() { + return value instanceof JsonObjectValue; + } + + public boolean _isUnknown() { + return value instanceof _UnknownValue; + } + + public Optional getText() { + if (isText()) { + return Optional.of(((TextValue) value).value); + } + return Optional.empty(); + } + + public Optional getJsonObject() { + if (isJsonObject()) { + return Optional.of(((JsonObjectValue) value).value); + } + return Optional.empty(); + } + + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); + } + + @JsonValue + private Value getValue() { + return this.value; + } + + public interface Visitor { + T visitText(TextResponseFormat2 text); + + T visitJsonObject(JsonResponseFormat2 jsonObject); + + T _visitUnknown(Object unknownType); + } + + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = _UnknownValue.class) + @JsonSubTypes({@JsonSubTypes.Type(TextValue.class), @JsonSubTypes.Type(JsonObjectValue.class)}) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } + + @JsonTypeName("text") + private static final class TextValue implements Value { + @JsonUnwrapped + private TextResponseFormat2 value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private TextValue() {} + + private TextValue(TextResponseFormat2 value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitText(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof TextValue && equalTo((TextValue) other); + } + + private boolean equalTo(TextValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "ResponseFormat2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("json_object") + private static final class JsonObjectValue implements Value { + @JsonUnwrapped + private JsonResponseFormat2 value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private JsonObjectValue() {} + + private JsonObjectValue(JsonResponseFormat2 value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitJsonObject(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof JsonObjectValue && equalTo((JsonObjectValue) other); + } + + private boolean equalTo(JsonObjectValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "ResponseFormat2{" + "value: " + value + "}"; + } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); + } + + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @java.lang.Override + public String toString() { + return "ResponseFormat2{" + "type: " + type + ", value: " + value + "}"; + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/Source.java b/src/main/java/com/cohere/api/resources/v2/types/Source.java new file mode 100644 index 0000000..a1c18fc --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/Source.java @@ -0,0 +1,200 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Objects; +import java.util.Optional; + +public final class Source { + private final Value value; + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private Source(Value value) { + this.value = value; + } + + public T visit(Visitor visitor) { + return value.visit(visitor); + } + + public static Source tool(ToolSource value) { + return new Source(new ToolValue(value)); + } + + public static Source document(DocumentSource value) { + return new Source(new DocumentValue(value)); + } + + public boolean isTool() { + return value instanceof ToolValue; + } + + public boolean isDocument() { + return value instanceof DocumentValue; + } + + public boolean _isUnknown() { + return value instanceof _UnknownValue; + } + + public Optional getTool() { + if (isTool()) { + return Optional.of(((ToolValue) value).value); + } + return Optional.empty(); + } + + public Optional getDocument() { + if (isDocument()) { + return Optional.of(((DocumentValue) value).value); + } + return Optional.empty(); + } + + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); + } + + @JsonValue + private Value getValue() { + return this.value; + } + + public interface Visitor { + T visitTool(ToolSource tool); + + T visitDocument(DocumentSource document); + + T _visitUnknown(Object unknownType); + } + + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = _UnknownValue.class) + @JsonSubTypes({@JsonSubTypes.Type(ToolValue.class), @JsonSubTypes.Type(DocumentValue.class)}) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } + + @JsonTypeName("tool") + private static final class ToolValue implements Value { + @JsonUnwrapped + private ToolSource value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ToolValue() {} + + private ToolValue(ToolSource value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitTool(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolValue && equalTo((ToolValue) other); + } + + private boolean equalTo(ToolValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "Source{" + "value: " + value + "}"; + } + } + + @JsonTypeName("document") + private static final class DocumentValue implements Value { + @JsonUnwrapped + private DocumentSource value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private DocumentValue() {} + + private DocumentValue(DocumentSource value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitDocument(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof DocumentValue && equalTo((DocumentValue) other); + } + + private boolean equalTo(DocumentValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "Source{" + "value: " + value + "}"; + } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); + } + + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @java.lang.Override + public String toString() { + return "Source{" + "type: " + type + ", value: " + value + "}"; + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/StreamedChatResponse2.java b/src/main/java/com/cohere/api/resources/v2/types/StreamedChatResponse2.java new file mode 100644 index 0000000..7d83081 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/StreamedChatResponse2.java @@ -0,0 +1,707 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Objects; +import java.util.Optional; + +public final class StreamedChatResponse2 { + private final Value value; + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private StreamedChatResponse2(Value value) { + this.value = value; + } + + public T visit(Visitor visitor) { + return value.visit(visitor); + } + + public static StreamedChatResponse2 messageStart(ChatMessageStartEvent value) { + return new StreamedChatResponse2(new MessageStartValue(value)); + } + + public static StreamedChatResponse2 contentStart(ChatContentStartEvent value) { + return new StreamedChatResponse2(new ContentStartValue(value)); + } + + public static StreamedChatResponse2 contentDelta(ChatContentDeltaEvent value) { + return new StreamedChatResponse2(new ContentDeltaValue(value)); + } + + public static StreamedChatResponse2 contentEnd(ChatContentEndEvent value) { + return new StreamedChatResponse2(new ContentEndValue(value)); + } + + public static StreamedChatResponse2 toolPlanDelta(ChatToolPlanDeltaEvent value) { + return new StreamedChatResponse2(new ToolPlanDeltaValue(value)); + } + + public static StreamedChatResponse2 toolCallStart(ChatToolCallStartEvent value) { + return new StreamedChatResponse2(new ToolCallStartValue(value)); + } + + public static StreamedChatResponse2 toolCallDelta(ChatToolCallDeltaEvent value) { + return new StreamedChatResponse2(new ToolCallDeltaValue(value)); + } + + public static StreamedChatResponse2 toolCallEnd(ChatToolCallEndEvent value) { + return new StreamedChatResponse2(new ToolCallEndValue(value)); + } + + public static StreamedChatResponse2 citationStart(CitationStartEvent value) { + return new StreamedChatResponse2(new CitationStartValue(value)); + } + + public static StreamedChatResponse2 citationEnd(CitationEndEvent value) { + return new StreamedChatResponse2(new CitationEndValue(value)); + } + + public static StreamedChatResponse2 messageEnd(ChatMessageEndEvent value) { + return new StreamedChatResponse2(new MessageEndValue(value)); + } + + public boolean isMessageStart() { + return value instanceof MessageStartValue; + } + + public boolean isContentStart() { + return value instanceof ContentStartValue; + } + + public boolean isContentDelta() { + return value instanceof ContentDeltaValue; + } + + public boolean isContentEnd() { + return value instanceof ContentEndValue; + } + + public boolean isToolPlanDelta() { + return value instanceof ToolPlanDeltaValue; + } + + public boolean isToolCallStart() { + return value instanceof ToolCallStartValue; + } + + public boolean isToolCallDelta() { + return value instanceof ToolCallDeltaValue; + } + + public boolean isToolCallEnd() { + return value instanceof ToolCallEndValue; + } + + public boolean isCitationStart() { + return value instanceof CitationStartValue; + } + + public boolean isCitationEnd() { + return value instanceof CitationEndValue; + } + + public boolean isMessageEnd() { + return value instanceof MessageEndValue; + } + + public boolean _isUnknown() { + return value instanceof _UnknownValue; + } + + public Optional getMessageStart() { + if (isMessageStart()) { + return Optional.of(((MessageStartValue) value).value); + } + return Optional.empty(); + } + + public Optional getContentStart() { + if (isContentStart()) { + return Optional.of(((ContentStartValue) value).value); + } + return Optional.empty(); + } + + public Optional getContentDelta() { + if (isContentDelta()) { + return Optional.of(((ContentDeltaValue) value).value); + } + return Optional.empty(); + } + + public Optional getContentEnd() { + if (isContentEnd()) { + return Optional.of(((ContentEndValue) value).value); + } + return Optional.empty(); + } + + public Optional getToolPlanDelta() { + if (isToolPlanDelta()) { + return Optional.of(((ToolPlanDeltaValue) value).value); + } + return Optional.empty(); + } + + public Optional getToolCallStart() { + if (isToolCallStart()) { + return Optional.of(((ToolCallStartValue) value).value); + } + return Optional.empty(); + } + + public Optional getToolCallDelta() { + if (isToolCallDelta()) { + return Optional.of(((ToolCallDeltaValue) value).value); + } + return Optional.empty(); + } + + public Optional getToolCallEnd() { + if (isToolCallEnd()) { + return Optional.of(((ToolCallEndValue) value).value); + } + return Optional.empty(); + } + + public Optional getCitationStart() { + if (isCitationStart()) { + return Optional.of(((CitationStartValue) value).value); + } + return Optional.empty(); + } + + public Optional getCitationEnd() { + if (isCitationEnd()) { + return Optional.of(((CitationEndValue) value).value); + } + return Optional.empty(); + } + + public Optional getMessageEnd() { + if (isMessageEnd()) { + return Optional.of(((MessageEndValue) value).value); + } + return Optional.empty(); + } + + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); + } + + @JsonValue + private Value getValue() { + return this.value; + } + + public interface Visitor { + T visitMessageStart(ChatMessageStartEvent messageStart); + + T visitContentStart(ChatContentStartEvent contentStart); + + T visitContentDelta(ChatContentDeltaEvent contentDelta); + + T visitContentEnd(ChatContentEndEvent contentEnd); + + T visitToolPlanDelta(ChatToolPlanDeltaEvent toolPlanDelta); + + T visitToolCallStart(ChatToolCallStartEvent toolCallStart); + + T visitToolCallDelta(ChatToolCallDeltaEvent toolCallDelta); + + T visitToolCallEnd(ChatToolCallEndEvent toolCallEnd); + + T visitCitationStart(CitationStartEvent citationStart); + + T visitCitationEnd(CitationEndEvent citationEnd); + + T visitMessageEnd(ChatMessageEndEvent messageEnd); + + T _visitUnknown(Object unknownType); + } + + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = _UnknownValue.class) + @JsonSubTypes({ + @JsonSubTypes.Type(MessageStartValue.class), + @JsonSubTypes.Type(ContentStartValue.class), + @JsonSubTypes.Type(ContentDeltaValue.class), + @JsonSubTypes.Type(ContentEndValue.class), + @JsonSubTypes.Type(ToolPlanDeltaValue.class), + @JsonSubTypes.Type(ToolCallStartValue.class), + @JsonSubTypes.Type(ToolCallDeltaValue.class), + @JsonSubTypes.Type(ToolCallEndValue.class), + @JsonSubTypes.Type(CitationStartValue.class), + @JsonSubTypes.Type(CitationEndValue.class), + @JsonSubTypes.Type(MessageEndValue.class) + }) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } + + @JsonTypeName("message-start") + private static final class MessageStartValue implements Value { + @JsonUnwrapped + private ChatMessageStartEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private MessageStartValue() {} + + private MessageStartValue(ChatMessageStartEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitMessageStart(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof MessageStartValue && equalTo((MessageStartValue) other); + } + + private boolean equalTo(MessageStartValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("content-start") + private static final class ContentStartValue implements Value { + @JsonUnwrapped + private ChatContentStartEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ContentStartValue() {} + + private ContentStartValue(ChatContentStartEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitContentStart(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ContentStartValue && equalTo((ContentStartValue) other); + } + + private boolean equalTo(ContentStartValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("content-delta") + private static final class ContentDeltaValue implements Value { + @JsonUnwrapped + private ChatContentDeltaEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ContentDeltaValue() {} + + private ContentDeltaValue(ChatContentDeltaEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitContentDelta(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ContentDeltaValue && equalTo((ContentDeltaValue) other); + } + + private boolean equalTo(ContentDeltaValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("content-end") + private static final class ContentEndValue implements Value { + @JsonUnwrapped + private ChatContentEndEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ContentEndValue() {} + + private ContentEndValue(ChatContentEndEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitContentEnd(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ContentEndValue && equalTo((ContentEndValue) other); + } + + private boolean equalTo(ContentEndValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("tool-plan-delta") + private static final class ToolPlanDeltaValue implements Value { + @JsonUnwrapped + private ChatToolPlanDeltaEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ToolPlanDeltaValue() {} + + private ToolPlanDeltaValue(ChatToolPlanDeltaEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitToolPlanDelta(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolPlanDeltaValue && equalTo((ToolPlanDeltaValue) other); + } + + private boolean equalTo(ToolPlanDeltaValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("tool-call-start") + private static final class ToolCallStartValue implements Value { + @JsonUnwrapped + private ChatToolCallStartEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ToolCallStartValue() {} + + private ToolCallStartValue(ChatToolCallStartEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitToolCallStart(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolCallStartValue && equalTo((ToolCallStartValue) other); + } + + private boolean equalTo(ToolCallStartValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("tool-call-delta") + private static final class ToolCallDeltaValue implements Value { + @JsonUnwrapped + private ChatToolCallDeltaEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ToolCallDeltaValue() {} + + private ToolCallDeltaValue(ChatToolCallDeltaEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitToolCallDelta(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolCallDeltaValue && equalTo((ToolCallDeltaValue) other); + } + + private boolean equalTo(ToolCallDeltaValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("tool-call-end") + private static final class ToolCallEndValue implements Value { + @JsonUnwrapped + private ChatToolCallEndEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ToolCallEndValue() {} + + private ToolCallEndValue(ChatToolCallEndEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitToolCallEnd(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolCallEndValue && equalTo((ToolCallEndValue) other); + } + + private boolean equalTo(ToolCallEndValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("citation-start") + private static final class CitationStartValue implements Value { + @JsonUnwrapped + private CitationStartEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private CitationStartValue() {} + + private CitationStartValue(CitationStartEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitCitationStart(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof CitationStartValue && equalTo((CitationStartValue) other); + } + + private boolean equalTo(CitationStartValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("citation-end") + private static final class CitationEndValue implements Value { + @JsonUnwrapped + private CitationEndEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private CitationEndValue() {} + + private CitationEndValue(CitationEndEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitCitationEnd(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof CitationEndValue && equalTo((CitationEndValue) other); + } + + private boolean equalTo(CitationEndValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + @JsonTypeName("message-end") + private static final class MessageEndValue implements Value { + @JsonUnwrapped + private ChatMessageEndEvent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private MessageEndValue() {} + + private MessageEndValue(ChatMessageEndEvent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitMessageEnd(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof MessageEndValue && equalTo((MessageEndValue) other); + } + + private boolean equalTo(MessageEndValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "value: " + value + "}"; + } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); + } + + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @java.lang.Override + public String toString() { + return "StreamedChatResponse2{" + "type: " + type + ", value: " + value + "}"; + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/SystemMessage.java b/src/main/java/com/cohere/api/resources/v2/types/SystemMessage.java new file mode 100644 index 0000000..59d33b6 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/SystemMessage.java @@ -0,0 +1,101 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = SystemMessage.Builder.class) +public final class SystemMessage { + private final SystemMessageContent content; + + private final Map additionalProperties; + + private SystemMessage(SystemMessageContent content, Map additionalProperties) { + this.content = content; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("content") + public SystemMessageContent getContent() { + return content; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof SystemMessage && equalTo((SystemMessage) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(SystemMessage other) { + return content.equals(other.content); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.content); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static ContentStage builder() { + return new Builder(); + } + + public interface ContentStage { + _FinalStage content(SystemMessageContent content); + + Builder from(SystemMessage other); + } + + public interface _FinalStage { + SystemMessage build(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements ContentStage, _FinalStage { + private SystemMessageContent content; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(SystemMessage other) { + content(other.getContent()); + return this; + } + + @java.lang.Override + @JsonSetter("content") + public _FinalStage content(SystemMessageContent content) { + this.content = content; + return this; + } + + @java.lang.Override + public SystemMessage build() { + return new SystemMessage(content, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/SystemMessageContent.java b/src/main/java/com/cohere/api/resources/v2/types/SystemMessageContent.java new file mode 100644 index 0000000..fdb4946 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/SystemMessageContent.java @@ -0,0 +1,97 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import java.io.IOException; +import java.util.List; +import java.util.Objects; + +@JsonDeserialize(using = SystemMessageContent.Deserializer.class) +public final class SystemMessageContent { + private final Object value; + + private final int type; + + private SystemMessageContent(Object value, int type) { + this.value = value; + this.type = type; + } + + @JsonValue + public Object get() { + return this.value; + } + + public T visit(Visitor visitor) { + if (this.type == 0) { + return visitor.visit((String) this.value); + } else if (this.type == 1) { + return visitor.visit((List) this.value); + } + throw new IllegalStateException("Failed to visit value. This should never happen."); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof SystemMessageContent && equalTo((SystemMessageContent) other); + } + + private boolean equalTo(SystemMessageContent other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return this.value.toString(); + } + + public static SystemMessageContent of(String value) { + return new SystemMessageContent(value, 0); + } + + public static SystemMessageContent of(List value) { + return new SystemMessageContent(value, 1); + } + + public interface Visitor { + T visit(String value); + + T visit(List value); + } + + static final class Deserializer extends StdDeserializer { + Deserializer() { + super(SystemMessageContent.class); + } + + @java.lang.Override + public SystemMessageContent deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + Object value = p.readValueAs(Object.class); + try { + return of(ObjectMappers.JSON_MAPPER.convertValue(value, String.class)); + } catch (IllegalArgumentException e) { + } + try { + return of(ObjectMappers.JSON_MAPPER.convertValue( + value, new TypeReference>() {})); + } catch (IllegalArgumentException e) { + } + throw new JsonParseException(p, "Failed to deserialize"); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/SystemMessageContentItem.java b/src/main/java/com/cohere/api/resources/v2/types/SystemMessageContentItem.java new file mode 100644 index 0000000..5a05e76 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/SystemMessageContentItem.java @@ -0,0 +1,145 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Objects; +import java.util.Optional; + +public final class SystemMessageContentItem { + private final Value value; + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private SystemMessageContentItem(Value value) { + this.value = value; + } + + public T visit(Visitor visitor) { + return value.visit(visitor); + } + + public static SystemMessageContentItem text(TextContent value) { + return new SystemMessageContentItem(new TextValue(value)); + } + + public boolean isText() { + return value instanceof TextValue; + } + + public boolean _isUnknown() { + return value instanceof _UnknownValue; + } + + public Optional getText() { + if (isText()) { + return Optional.of(((TextValue) value).value); + } + return Optional.empty(); + } + + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); + } + + @JsonValue + private Value getValue() { + return this.value; + } + + public interface Visitor { + T visitText(TextContent text); + + T _visitUnknown(Object unknownType); + } + + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = _UnknownValue.class) + @JsonSubTypes(@JsonSubTypes.Type(TextValue.class)) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } + + @JsonTypeName("text") + private static final class TextValue implements Value { + @JsonUnwrapped + private TextContent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private TextValue() {} + + private TextValue(TextContent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitText(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof TextValue && equalTo((TextValue) other); + } + + private boolean equalTo(TextValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "SystemMessageContentItem{" + "value: " + value + "}"; + } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); + } + + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @java.lang.Override + public String toString() { + return "SystemMessageContentItem{" + "type: " + type + ", value: " + value + "}"; + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/TextContent.java b/src/main/java/com/cohere/api/resources/v2/types/TextContent.java new file mode 100644 index 0000000..352a9f1 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/TextContent.java @@ -0,0 +1,101 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = TextContent.Builder.class) +public final class TextContent { + private final String text; + + private final Map additionalProperties; + + private TextContent(String text, Map additionalProperties) { + this.text = text; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("text") + public String getText() { + return text; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof TextContent && equalTo((TextContent) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(TextContent other) { + return text.equals(other.text); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.text); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static TextStage builder() { + return new Builder(); + } + + public interface TextStage { + _FinalStage text(String text); + + Builder from(TextContent other); + } + + public interface _FinalStage { + TextContent build(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements TextStage, _FinalStage { + private String text; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(TextContent other) { + text(other.getText()); + return this; + } + + @java.lang.Override + @JsonSetter("text") + public _FinalStage text(String text) { + this.text = text; + return this; + } + + @java.lang.Override + public TextContent build() { + return new TextContent(text, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/TextResponseFormat2.java b/src/main/java/com/cohere/api/resources/v2/types/TextResponseFormat2.java new file mode 100644 index 0000000..31f0b03 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/TextResponseFormat2.java @@ -0,0 +1,59 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = TextResponseFormat2.Builder.class) +public final class TextResponseFormat2 { + private final Map additionalProperties; + + private TextResponseFormat2(Map additionalProperties) { + this.additionalProperties = additionalProperties; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof TextResponseFormat2; + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + @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 { + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(TextResponseFormat2 other) { + return this; + } + + public TextResponseFormat2 build() { + return new TextResponseFormat2(additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/Texts.java b/src/main/java/com/cohere/api/resources/v2/types/Texts.java new file mode 100644 index 0000000..f06a4e7 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/Texts.java @@ -0,0 +1,307 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +import com.cohere.api.types.EmbeddingType; +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 = Texts.Builder.class) +public final class Texts { + private final List texts; + + private final String model; + + private final Optional> embeddingTypes; + + private final Optional truncate; + + private final Map additionalProperties; + + private Texts( + List texts, + String model, + Optional> embeddingTypes, + Optional truncate, + Map additionalProperties) { + this.texts = texts; + this.model = model; + this.embeddingTypes = embeddingTypes; + this.truncate = truncate; + this.additionalProperties = additionalProperties; + } + + /** + * @return An array of strings for the model to embed. Maximum number of texts per call is 96. We recommend reducing the length of each text to be under 512 tokens for optimal quality. + */ + @JsonProperty("texts") + public List getTexts() { + return texts; + } + + /** + * @return Defaults to embed-english-v2.0 + *

The identifier of the model. Smaller "light" models are faster, while larger models will perform better. Custom models can also be supplied with their full ID.

+ *

Available models and corresponding embedding dimensions:

+ *
    + *
  • + *

    embed-english-v3.0 1024

    + *
  • + *
  • + *

    embed-multilingual-v3.0 1024

    + *
  • + *
  • + *

    embed-english-light-v3.0 384

    + *
  • + *
  • + *

    embed-multilingual-light-v3.0 384

    + *
  • + *
  • + *

    embed-english-v2.0 4096

    + *
  • + *
  • + *

    embed-english-light-v2.0 1024

    + *
  • + *
  • + *

    embed-multilingual-v2.0 768

    + *
  • + *
+ */ + @JsonProperty("model") + public String getModel() { + return model; + } + + /** + * @return Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types. + *
    + *
  • "float": Use this when you want to get back the default float embeddings. Valid for all models.
  • + *
  • "int8": Use this when you want to get back signed int8 embeddings. Valid for only v3 models.
  • + *
  • "uint8": Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models.
  • + *
  • "binary": Use this when you want to get back signed binary embeddings. Valid for only v3 models.
  • + *
  • "ubinary": Use this when you want to get back unsigned binary embeddings. Valid for only v3 models.
  • + *
+ */ + @JsonProperty("embedding_types") + public Optional> getEmbeddingTypes() { + return embeddingTypes; + } + + /** + * @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 Texts && equalTo((Texts) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(Texts other) { + return texts.equals(other.texts) + && model.equals(other.model) + && embeddingTypes.equals(other.embeddingTypes) + && truncate.equals(other.truncate); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.texts, this.model, this.embeddingTypes, this.truncate); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static ModelStage builder() { + return new Builder(); + } + + public interface ModelStage { + _FinalStage model(String model); + + Builder from(Texts other); + } + + public interface _FinalStage { + Texts build(); + + _FinalStage texts(List texts); + + _FinalStage addTexts(String texts); + + _FinalStage addAllTexts(List texts); + + _FinalStage embeddingTypes(Optional> embeddingTypes); + + _FinalStage embeddingTypes(List embeddingTypes); + + _FinalStage truncate(Optional truncate); + + _FinalStage truncate(TextsTruncate truncate); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements ModelStage, _FinalStage { + private String model; + + private Optional truncate = Optional.empty(); + + private Optional> embeddingTypes = Optional.empty(); + + private List texts = new ArrayList<>(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(Texts other) { + texts(other.getTexts()); + model(other.getModel()); + embeddingTypes(other.getEmbeddingTypes()); + truncate(other.getTruncate()); + return this; + } + + /** + *

Defaults to embed-english-v2.0

+ *

The identifier of the model. Smaller "light" models are faster, while larger models will perform better. Custom models can also be supplied with their full ID.

+ *

Available models and corresponding embedding dimensions:

+ *
    + *
  • + *

    embed-english-v3.0 1024

    + *
  • + *
  • + *

    embed-multilingual-v3.0 1024

    + *
  • + *
  • + *

    embed-english-light-v3.0 384

    + *
  • + *
  • + *

    embed-multilingual-light-v3.0 384

    + *
  • + *
  • + *

    embed-english-v2.0 4096

    + *
  • + *
  • + *

    embed-english-light-v2.0 1024

    + *
  • + *
  • + *

    embed-multilingual-v2.0 768

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

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.

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

Specifies the types of embeddings you want to get back. Not required and default is None, which returns the Embed Floats response type. Can be one or more of the following types.

+ *
    + *
  • "float": Use this when you want to get back the default float embeddings. Valid for all models.
  • + *
  • "int8": Use this when you want to get back signed int8 embeddings. Valid for only v3 models.
  • + *
  • "uint8": Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models.
  • + *
  • "binary": Use this when you want to get back signed binary embeddings. Valid for only v3 models.
  • + *
  • "ubinary": Use this when you want to get back unsigned binary embeddings. Valid for only v3 models.
  • + *
+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage embeddingTypes(List embeddingTypes) { + this.embeddingTypes = Optional.of(embeddingTypes); + return this; + } + + @java.lang.Override + @JsonSetter(value = "embedding_types", nulls = Nulls.SKIP) + public _FinalStage embeddingTypes(Optional> embeddingTypes) { + this.embeddingTypes = embeddingTypes; + return this; + } + + /** + *

An array of strings for the model to embed. Maximum number of texts per call is 96. We recommend reducing the length of each text to be under 512 tokens for optimal quality.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage addAllTexts(List texts) { + this.texts.addAll(texts); + return this; + } + + /** + *

An array of strings for the model to embed. Maximum number of texts per call is 96. We recommend reducing the length of each text to be under 512 tokens for optimal quality.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + public _FinalStage addTexts(String texts) { + this.texts.add(texts); + return this; + } + + @java.lang.Override + @JsonSetter(value = "texts", nulls = Nulls.SKIP) + public _FinalStage texts(List texts) { + this.texts.clear(); + this.texts.addAll(texts); + return this; + } + + @java.lang.Override + public Texts build() { + return new Texts(texts, model, embeddingTypes, truncate, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/TextsTruncate.java b/src/main/java/com/cohere/api/resources/v2/types/TextsTruncate.java new file mode 100644 index 0000000..c31137b --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/TextsTruncate.java @@ -0,0 +1,26 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum TextsTruncate { + NONE("NONE"), + + START("START"), + + END("END"); + + private final String value; + + TextsTruncate(String value) { + this.value = value; + } + + @JsonValue + @java.lang.Override + public String toString() { + return this.value; + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/Tool2.java b/src/main/java/com/cohere/api/resources/v2/types/Tool2.java new file mode 100644 index 0000000..a300063 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/Tool2.java @@ -0,0 +1,120 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = Tool2.Builder.class) +public final class Tool2 { + private final Optional type; + + private final Optional function; + + private final Map additionalProperties; + + private Tool2(Optional type, Optional function, Map additionalProperties) { + this.type = type; + this.function = function; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("type") + public Optional getType() { + return type; + } + + /** + * @return The function to be executed. + */ + @JsonProperty("function") + public Optional getFunction() { + return function; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof Tool2 && equalTo((Tool2) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(Tool2 other) { + return type.equals(other.type) && function.equals(other.function); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.function); + } + + @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 Optional type = Optional.empty(); + + private Optional function = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(Tool2 other) { + type(other.getType()); + function(other.getFunction()); + return this; + } + + @JsonSetter(value = "type", nulls = Nulls.SKIP) + public Builder type(Optional type) { + this.type = type; + return this; + } + + public Builder type(String type) { + this.type = Optional.of(type); + return this; + } + + @JsonSetter(value = "function", nulls = Nulls.SKIP) + public Builder function(Optional function) { + this.function = function; + return this; + } + + public Builder function(Tool2Function function) { + this.function = Optional.of(function); + return this; + } + + public Tool2 build() { + return new Tool2(type, function, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/Tool2Function.java b/src/main/java/com/cohere/api/resources/v2/types/Tool2Function.java new file mode 100644 index 0000000..c75eac8 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/Tool2Function.java @@ -0,0 +1,152 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = Tool2Function.Builder.class) +public final class Tool2Function { + private final Optional name; + + private final Optional description; + + private final Optional> parameters; + + private final Map additionalProperties; + + private Tool2Function( + Optional name, + Optional description, + Optional> parameters, + Map additionalProperties) { + this.name = name; + this.description = description; + this.parameters = parameters; + this.additionalProperties = additionalProperties; + } + + /** + * @return The name of the function. + */ + @JsonProperty("name") + public Optional getName() { + return name; + } + + /** + * @return The description of the function. + */ + @JsonProperty("description") + public Optional getDescription() { + return description; + } + + /** + * @return The parameters of the function as a JSON schema. + */ + @JsonProperty("parameters") + public Optional> getParameters() { + return parameters; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof Tool2Function && equalTo((Tool2Function) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(Tool2Function other) { + return name.equals(other.name) && description.equals(other.description) && parameters.equals(other.parameters); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.name, this.description, this.parameters); + } + + @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 Optional name = Optional.empty(); + + private Optional description = Optional.empty(); + + private Optional> parameters = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(Tool2Function other) { + name(other.getName()); + description(other.getDescription()); + parameters(other.getParameters()); + return this; + } + + @JsonSetter(value = "name", nulls = Nulls.SKIP) + public Builder name(Optional name) { + this.name = name; + return this; + } + + public Builder name(String name) { + this.name = Optional.of(name); + return this; + } + + @JsonSetter(value = "description", nulls = Nulls.SKIP) + public Builder description(Optional description) { + this.description = description; + return this; + } + + public Builder description(String description) { + this.description = Optional.of(description); + return this; + } + + @JsonSetter(value = "parameters", nulls = Nulls.SKIP) + public Builder parameters(Optional> parameters) { + this.parameters = parameters; + return this; + } + + public Builder parameters(Map parameters) { + this.parameters = Optional.of(parameters); + return this; + } + + public Tool2Function build() { + return new Tool2Function(name, description, parameters, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ToolCall2.java b/src/main/java/com/cohere/api/resources/v2/types/ToolCall2.java new file mode 100644 index 0000000..dd18534 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ToolCall2.java @@ -0,0 +1,143 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ToolCall2.Builder.class) +public final class ToolCall2 { + private final Optional id; + + private final Optional type; + + private final Optional function; + + private final Map additionalProperties; + + private ToolCall2( + Optional id, + Optional type, + Optional function, + Map additionalProperties) { + this.id = id; + this.type = type; + this.function = function; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("id") + public Optional getId() { + return id; + } + + @JsonProperty("type") + public Optional getType() { + return type; + } + + @JsonProperty("function") + public Optional getFunction() { + return function; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolCall2 && equalTo((ToolCall2) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ToolCall2 other) { + return id.equals(other.id) && type.equals(other.type) && function.equals(other.function); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.id, this.type, this.function); + } + + @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 Optional id = Optional.empty(); + + private Optional type = Optional.empty(); + + private Optional function = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ToolCall2 other) { + id(other.getId()); + type(other.getType()); + function(other.getFunction()); + return this; + } + + @JsonSetter(value = "id", nulls = Nulls.SKIP) + public Builder id(Optional id) { + this.id = id; + return this; + } + + public Builder id(String id) { + this.id = Optional.of(id); + return this; + } + + @JsonSetter(value = "type", nulls = Nulls.SKIP) + public Builder type(Optional type) { + this.type = type; + return this; + } + + public Builder type(String type) { + this.type = Optional.of(type); + return this; + } + + @JsonSetter(value = "function", nulls = Nulls.SKIP) + public Builder function(Optional function) { + this.function = function; + return this; + } + + public Builder function(ToolCall2Function function) { + this.function = Optional.of(function); + return this; + } + + public ToolCall2 build() { + return new ToolCall2(id, type, function, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ToolCall2Function.java b/src/main/java/com/cohere/api/resources/v2/types/ToolCall2Function.java new file mode 100644 index 0000000..5c89f61 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ToolCall2Function.java @@ -0,0 +1,118 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ToolCall2Function.Builder.class) +public final class ToolCall2Function { + private final Optional name; + + private final Optional arguments; + + private final Map additionalProperties; + + private ToolCall2Function( + Optional name, Optional arguments, Map additionalProperties) { + this.name = name; + this.arguments = arguments; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("name") + public Optional getName() { + return name; + } + + @JsonProperty("arguments") + public Optional getArguments() { + return arguments; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolCall2Function && equalTo((ToolCall2Function) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ToolCall2Function other) { + return name.equals(other.name) && arguments.equals(other.arguments); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.name, this.arguments); + } + + @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 Optional name = Optional.empty(); + + private Optional arguments = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ToolCall2Function other) { + name(other.getName()); + arguments(other.getArguments()); + return this; + } + + @JsonSetter(value = "name", nulls = Nulls.SKIP) + public Builder name(Optional name) { + this.name = name; + return this; + } + + public Builder name(String name) { + this.name = Optional.of(name); + return this; + } + + @JsonSetter(value = "arguments", nulls = Nulls.SKIP) + public Builder arguments(Optional arguments) { + this.arguments = arguments; + return this; + } + + public Builder arguments(String arguments) { + this.arguments = Optional.of(arguments); + return this; + } + + public ToolCall2Function build() { + return new ToolCall2Function(name, arguments, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ToolContent.java b/src/main/java/com/cohere/api/resources/v2/types/ToolContent.java new file mode 100644 index 0000000..f775d57 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ToolContent.java @@ -0,0 +1,200 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Objects; +import java.util.Optional; + +public final class ToolContent { + private final Value value; + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private ToolContent(Value value) { + this.value = value; + } + + public T visit(Visitor visitor) { + return value.visit(visitor); + } + + public static ToolContent text(TextContent value) { + return new ToolContent(new TextValue(value)); + } + + public static ToolContent document(DocumentContent value) { + return new ToolContent(new DocumentValue(value)); + } + + public boolean isText() { + return value instanceof TextValue; + } + + public boolean isDocument() { + return value instanceof DocumentValue; + } + + public boolean _isUnknown() { + return value instanceof _UnknownValue; + } + + public Optional getText() { + if (isText()) { + return Optional.of(((TextValue) value).value); + } + return Optional.empty(); + } + + public Optional getDocument() { + if (isDocument()) { + return Optional.of(((DocumentValue) value).value); + } + return Optional.empty(); + } + + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); + } + + @JsonValue + private Value getValue() { + return this.value; + } + + public interface Visitor { + T visitText(TextContent text); + + T visitDocument(DocumentContent document); + + T _visitUnknown(Object unknownType); + } + + @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true, defaultImpl = _UnknownValue.class) + @JsonSubTypes({@JsonSubTypes.Type(TextValue.class), @JsonSubTypes.Type(DocumentValue.class)}) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } + + @JsonTypeName("text") + private static final class TextValue implements Value { + @JsonUnwrapped + private TextContent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private TextValue() {} + + private TextValue(TextContent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitText(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof TextValue && equalTo((TextValue) other); + } + + private boolean equalTo(TextValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "ToolContent{" + "value: " + value + "}"; + } + } + + @JsonTypeName("document") + private static final class DocumentValue implements Value { + @JsonUnwrapped + private DocumentContent value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private DocumentValue() {} + + private DocumentValue(DocumentContent value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitDocument(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof DocumentValue && equalTo((DocumentValue) other); + } + + private boolean equalTo(DocumentValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "ToolContent{" + "value: " + value + "}"; + } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); + } + + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @java.lang.Override + public String toString() { + return "ToolContent{" + "type: " + type + ", value: " + value + "}"; + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ToolMessage2.java b/src/main/java/com/cohere/api/resources/v2/types/ToolMessage2.java new file mode 100644 index 0000000..c258be6 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ToolMessage2.java @@ -0,0 +1,138 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ToolMessage2.Builder.class) +public final class ToolMessage2 { + private final String toolCallId; + + private final ToolMessage2ToolContent toolContent; + + private final Map additionalProperties; + + private ToolMessage2( + String toolCallId, ToolMessage2ToolContent toolContent, Map additionalProperties) { + this.toolCallId = toolCallId; + this.toolContent = toolContent; + this.additionalProperties = additionalProperties; + } + + /** + * @return The id of the associated tool call that has provided the given content + */ + @JsonProperty("tool_call_id") + public String getToolCallId() { + return toolCallId; + } + + /** + * @return A single or list of outputs from a tool. The content should formatted as a JSON object string, or a list of tool content blocks + */ + @JsonProperty("tool_content") + public ToolMessage2ToolContent getToolContent() { + return toolContent; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolMessage2 && equalTo((ToolMessage2) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ToolMessage2 other) { + return toolCallId.equals(other.toolCallId) && toolContent.equals(other.toolContent); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.toolCallId, this.toolContent); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static ToolCallIdStage builder() { + return new Builder(); + } + + public interface ToolCallIdStage { + ToolContentStage toolCallId(String toolCallId); + + Builder from(ToolMessage2 other); + } + + public interface ToolContentStage { + _FinalStage toolContent(ToolMessage2ToolContent toolContent); + } + + public interface _FinalStage { + ToolMessage2 build(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements ToolCallIdStage, ToolContentStage, _FinalStage { + private String toolCallId; + + private ToolMessage2ToolContent toolContent; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(ToolMessage2 other) { + toolCallId(other.getToolCallId()); + toolContent(other.getToolContent()); + return this; + } + + /** + *

The id of the associated tool call that has provided the given content

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

A single or list of outputs from a tool. The content should formatted as a JSON object string, or a list of tool content blocks

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("tool_content") + public _FinalStage toolContent(ToolMessage2ToolContent toolContent) { + this.toolContent = toolContent; + return this; + } + + @java.lang.Override + public ToolMessage2 build() { + return new ToolMessage2(toolCallId, toolContent, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ToolMessage2ToolContent.java b/src/main/java/com/cohere/api/resources/v2/types/ToolMessage2ToolContent.java new file mode 100644 index 0000000..ad403bf --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ToolMessage2ToolContent.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import java.io.IOException; +import java.util.List; +import java.util.Objects; + +@JsonDeserialize(using = ToolMessage2ToolContent.Deserializer.class) +public final class ToolMessage2ToolContent { + private final Object value; + + private final int type; + + private ToolMessage2ToolContent(Object value, int type) { + this.value = value; + this.type = type; + } + + @JsonValue + public Object get() { + return this.value; + } + + public T visit(Visitor visitor) { + if (this.type == 0) { + return visitor.visit((String) this.value); + } else if (this.type == 1) { + return visitor.visit((List) this.value); + } + throw new IllegalStateException("Failed to visit value. This should never happen."); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolMessage2ToolContent && equalTo((ToolMessage2ToolContent) other); + } + + private boolean equalTo(ToolMessage2ToolContent other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return this.value.toString(); + } + + public static ToolMessage2ToolContent of(String value) { + return new ToolMessage2ToolContent(value, 0); + } + + public static ToolMessage2ToolContent of(List value) { + return new ToolMessage2ToolContent(value, 1); + } + + public interface Visitor { + T visit(String value); + + T visit(List value); + } + + static final class Deserializer extends StdDeserializer { + Deserializer() { + super(ToolMessage2ToolContent.class); + } + + @java.lang.Override + public ToolMessage2ToolContent deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + Object value = p.readValueAs(Object.class); + try { + return of(ObjectMappers.JSON_MAPPER.convertValue(value, String.class)); + } catch (IllegalArgumentException e) { + } + try { + return of(ObjectMappers.JSON_MAPPER.convertValue(value, new TypeReference>() {})); + } catch (IllegalArgumentException e) { + } + throw new JsonParseException(p, "Failed to deserialize"); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/ToolSource.java b/src/main/java/com/cohere/api/resources/v2/types/ToolSource.java new file mode 100644 index 0000000..967faac --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/ToolSource.java @@ -0,0 +1,121 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = ToolSource.Builder.class) +public final class ToolSource { + private final Optional id; + + private final Optional> toolOutput; + + private final Map additionalProperties; + + private ToolSource( + Optional id, Optional> toolOutput, Map additionalProperties) { + this.id = id; + this.toolOutput = toolOutput; + this.additionalProperties = additionalProperties; + } + + /** + * @return The unique identifier of the document + */ + @JsonProperty("id") + public Optional getId() { + return id; + } + + @JsonProperty("tool_output") + public Optional> getToolOutput() { + return toolOutput; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ToolSource && equalTo((ToolSource) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(ToolSource other) { + return id.equals(other.id) && toolOutput.equals(other.toolOutput); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.id, this.toolOutput); + } + + @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 Optional id = Optional.empty(); + + private Optional> toolOutput = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(ToolSource other) { + id(other.getId()); + toolOutput(other.getToolOutput()); + return this; + } + + @JsonSetter(value = "id", nulls = Nulls.SKIP) + public Builder id(Optional id) { + this.id = id; + return this; + } + + public Builder id(String id) { + this.id = Optional.of(id); + return this; + } + + @JsonSetter(value = "tool_output", nulls = Nulls.SKIP) + public Builder toolOutput(Optional> toolOutput) { + this.toolOutput = toolOutput; + return this; + } + + public Builder toolOutput(Map toolOutput) { + this.toolOutput = Optional.of(toolOutput); + return this; + } + + public ToolSource build() { + return new ToolSource(id, toolOutput, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/Usage.java b/src/main/java/com/cohere/api/resources/v2/types/Usage.java new file mode 100644 index 0000000..c999cef --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/Usage.java @@ -0,0 +1,120 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = Usage.Builder.class) +public final class Usage { + private final Optional billedUnits; + + private final Optional tokens; + + private final Map additionalProperties; + + private Usage( + Optional billedUnits, + Optional tokens, + Map additionalProperties) { + this.billedUnits = billedUnits; + this.tokens = tokens; + this.additionalProperties = additionalProperties; + } + + @JsonProperty("billed_units") + public Optional getBilledUnits() { + return billedUnits; + } + + @JsonProperty("tokens") + public Optional getTokens() { + return tokens; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof Usage && equalTo((Usage) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(Usage other) { + return billedUnits.equals(other.billedUnits) && tokens.equals(other.tokens); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.billedUnits, this.tokens); + } + + @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 Optional billedUnits = Optional.empty(); + + private Optional tokens = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(Usage other) { + billedUnits(other.getBilledUnits()); + tokens(other.getTokens()); + return this; + } + + @JsonSetter(value = "billed_units", nulls = Nulls.SKIP) + public Builder billedUnits(Optional billedUnits) { + this.billedUnits = billedUnits; + return this; + } + + public Builder billedUnits(UsageBilledUnits billedUnits) { + this.billedUnits = Optional.of(billedUnits); + return this; + } + + @JsonSetter(value = "tokens", nulls = Nulls.SKIP) + public Builder tokens(Optional tokens) { + this.tokens = tokens; + return this; + } + + public Builder tokens(UsageTokens tokens) { + this.tokens = Optional.of(tokens); + return this; + } + + public Usage build() { + return new Usage(billedUnits, tokens, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/UsageBilledUnits.java b/src/main/java/com/cohere/api/resources/v2/types/UsageBilledUnits.java new file mode 100644 index 0000000..c6d2d09 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/UsageBilledUnits.java @@ -0,0 +1,181 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = UsageBilledUnits.Builder.class) +public final class UsageBilledUnits { + private final Optional inputTokens; + + private final Optional outputTokens; + + private final Optional searchUnits; + + private final Optional classifications; + + private final Map additionalProperties; + + private UsageBilledUnits( + Optional inputTokens, + Optional outputTokens, + Optional searchUnits, + Optional classifications, + Map additionalProperties) { + this.inputTokens = inputTokens; + this.outputTokens = outputTokens; + this.searchUnits = searchUnits; + this.classifications = classifications; + this.additionalProperties = additionalProperties; + } + + /** + * @return The number of billed input tokens. + */ + @JsonProperty("input_tokens") + public Optional getInputTokens() { + return inputTokens; + } + + /** + * @return The number of billed output tokens. + */ + @JsonProperty("output_tokens") + public Optional getOutputTokens() { + return outputTokens; + } + + /** + * @return The number of billed search units. + */ + @JsonProperty("search_units") + public Optional getSearchUnits() { + return searchUnits; + } + + /** + * @return The number of billed classifications units. + */ + @JsonProperty("classifications") + public Optional getClassifications() { + return classifications; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof UsageBilledUnits && equalTo((UsageBilledUnits) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(UsageBilledUnits other) { + return inputTokens.equals(other.inputTokens) + && outputTokens.equals(other.outputTokens) + && searchUnits.equals(other.searchUnits) + && classifications.equals(other.classifications); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.inputTokens, this.outputTokens, this.searchUnits, this.classifications); + } + + @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 Optional inputTokens = Optional.empty(); + + private Optional outputTokens = Optional.empty(); + + private Optional searchUnits = Optional.empty(); + + private Optional classifications = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(UsageBilledUnits other) { + inputTokens(other.getInputTokens()); + outputTokens(other.getOutputTokens()); + searchUnits(other.getSearchUnits()); + classifications(other.getClassifications()); + return this; + } + + @JsonSetter(value = "input_tokens", nulls = Nulls.SKIP) + public Builder inputTokens(Optional inputTokens) { + this.inputTokens = inputTokens; + return this; + } + + public Builder inputTokens(Double inputTokens) { + this.inputTokens = Optional.of(inputTokens); + return this; + } + + @JsonSetter(value = "output_tokens", nulls = Nulls.SKIP) + public Builder outputTokens(Optional outputTokens) { + this.outputTokens = outputTokens; + return this; + } + + public Builder outputTokens(Double outputTokens) { + this.outputTokens = Optional.of(outputTokens); + return this; + } + + @JsonSetter(value = "search_units", nulls = Nulls.SKIP) + public Builder searchUnits(Optional searchUnits) { + this.searchUnits = searchUnits; + return this; + } + + public Builder searchUnits(Double searchUnits) { + this.searchUnits = Optional.of(searchUnits); + return this; + } + + @JsonSetter(value = "classifications", nulls = Nulls.SKIP) + public Builder classifications(Optional classifications) { + this.classifications = classifications; + return this; + } + + public Builder classifications(Double classifications) { + this.classifications = Optional.of(classifications); + return this; + } + + public UsageBilledUnits build() { + return new UsageBilledUnits(inputTokens, outputTokens, searchUnits, classifications, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/UsageTokens.java b/src/main/java/com/cohere/api/resources/v2/types/UsageTokens.java new file mode 100644 index 0000000..ba39c85 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/UsageTokens.java @@ -0,0 +1,124 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.Map; +import java.util.Objects; +import java.util.Optional; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = UsageTokens.Builder.class) +public final class UsageTokens { + private final Optional inputTokens; + + private final Optional outputTokens; + + private final Map additionalProperties; + + private UsageTokens( + Optional inputTokens, Optional outputTokens, Map additionalProperties) { + this.inputTokens = inputTokens; + this.outputTokens = outputTokens; + this.additionalProperties = additionalProperties; + } + + /** + * @return The number of tokens used as input to the model. + */ + @JsonProperty("input_tokens") + public Optional getInputTokens() { + return inputTokens; + } + + /** + * @return The number of tokens produced by the model. + */ + @JsonProperty("output_tokens") + public Optional getOutputTokens() { + return outputTokens; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof UsageTokens && equalTo((UsageTokens) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(UsageTokens other) { + return inputTokens.equals(other.inputTokens) && outputTokens.equals(other.outputTokens); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.inputTokens, this.outputTokens); + } + + @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 Optional inputTokens = Optional.empty(); + + private Optional outputTokens = Optional.empty(); + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + public Builder from(UsageTokens other) { + inputTokens(other.getInputTokens()); + outputTokens(other.getOutputTokens()); + return this; + } + + @JsonSetter(value = "input_tokens", nulls = Nulls.SKIP) + public Builder inputTokens(Optional inputTokens) { + this.inputTokens = inputTokens; + return this; + } + + public Builder inputTokens(Double inputTokens) { + this.inputTokens = Optional.of(inputTokens); + return this; + } + + @JsonSetter(value = "output_tokens", nulls = Nulls.SKIP) + public Builder outputTokens(Optional outputTokens) { + this.outputTokens = outputTokens; + return this; + } + + public Builder outputTokens(Double outputTokens) { + this.outputTokens = Optional.of(outputTokens); + return this; + } + + public UsageTokens build() { + return new UsageTokens(inputTokens, outputTokens, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/UserMessage.java b/src/main/java/com/cohere/api/resources/v2/types/UserMessage.java new file mode 100644 index 0000000..cc696cc --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/UserMessage.java @@ -0,0 +1,110 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +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.databind.annotation.JsonDeserialize; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@JsonDeserialize(builder = UserMessage.Builder.class) +public final class UserMessage { + private final UserMessageContent content; + + private final Map additionalProperties; + + private UserMessage(UserMessageContent content, Map additionalProperties) { + this.content = content; + this.additionalProperties = additionalProperties; + } + + /** + * @return The content of the message. This can be a string or a list of content blocks. + * If a string is provided, it will be treated as a text content block. + */ + @JsonProperty("content") + public UserMessageContent getContent() { + return content; + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof UserMessage && equalTo((UserMessage) other); + } + + @JsonAnyGetter + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + private boolean equalTo(UserMessage other) { + return content.equals(other.content); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.content); + } + + @java.lang.Override + public String toString() { + return ObjectMappers.stringify(this); + } + + public static ContentStage builder() { + return new Builder(); + } + + public interface ContentStage { + _FinalStage content(UserMessageContent content); + + Builder from(UserMessage other); + } + + public interface _FinalStage { + UserMessage build(); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static final class Builder implements ContentStage, _FinalStage { + private UserMessageContent content; + + @JsonAnySetter + private Map additionalProperties = new HashMap<>(); + + private Builder() {} + + @java.lang.Override + public Builder from(UserMessage other) { + content(other.getContent()); + return this; + } + + /** + *

The content of the message. This can be a string or a list of content blocks. + * If a string is provided, it will be treated as a text content block.

+ * @return Reference to {@code this} so that method calls can be chained together. + */ + @java.lang.Override + @JsonSetter("content") + public _FinalStage content(UserMessageContent content) { + this.content = content; + return this; + } + + @java.lang.Override + public UserMessage build() { + return new UserMessage(content, additionalProperties); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/UserMessageContent.java b/src/main/java/com/cohere/api/resources/v2/types/UserMessageContent.java new file mode 100644 index 0000000..27d8a37 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/UserMessageContent.java @@ -0,0 +1,96 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import java.io.IOException; +import java.util.List; +import java.util.Objects; + +@JsonDeserialize(using = UserMessageContent.Deserializer.class) +public final class UserMessageContent { + private final Object value; + + private final int type; + + private UserMessageContent(Object value, int type) { + this.value = value; + this.type = type; + } + + @JsonValue + public Object get() { + return this.value; + } + + public T visit(Visitor visitor) { + if (this.type == 0) { + return visitor.visit((String) this.value); + } else if (this.type == 1) { + return visitor.visit((List) this.value); + } + throw new IllegalStateException("Failed to visit value. This should never happen."); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof UserMessageContent && equalTo((UserMessageContent) other); + } + + private boolean equalTo(UserMessageContent other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return this.value.toString(); + } + + public static UserMessageContent of(String value) { + return new UserMessageContent(value, 0); + } + + public static UserMessageContent of(List value) { + return new UserMessageContent(value, 1); + } + + public interface Visitor { + T visit(String value); + + T visit(List value); + } + + static final class Deserializer extends StdDeserializer { + Deserializer() { + super(UserMessageContent.class); + } + + @java.lang.Override + public UserMessageContent deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + Object value = p.readValueAs(Object.class); + try { + return of(ObjectMappers.JSON_MAPPER.convertValue(value, String.class)); + } catch (IllegalArgumentException e) { + } + try { + return of(ObjectMappers.JSON_MAPPER.convertValue(value, new TypeReference>() {})); + } catch (IllegalArgumentException e) { + } + throw new JsonParseException(p, "Failed to deserialize"); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/V2ChatRequestDocumentsItem.java b/src/main/java/com/cohere/api/resources/v2/types/V2ChatRequestDocumentsItem.java new file mode 100644 index 0000000..be4466f --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/V2ChatRequestDocumentsItem.java @@ -0,0 +1,94 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import java.io.IOException; +import java.util.Objects; + +@JsonDeserialize(using = V2ChatRequestDocumentsItem.Deserializer.class) +public final class V2ChatRequestDocumentsItem { + private final Object value; + + private final int type; + + private V2ChatRequestDocumentsItem(Object value, int type) { + this.value = value; + this.type = type; + } + + @JsonValue + public Object get() { + return this.value; + } + + public T visit(Visitor visitor) { + if (this.type == 0) { + return visitor.visit((String) this.value); + } else if (this.type == 1) { + return visitor.visit((Document) this.value); + } + throw new IllegalStateException("Failed to visit value. This should never happen."); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof V2ChatRequestDocumentsItem && equalTo((V2ChatRequestDocumentsItem) other); + } + + private boolean equalTo(V2ChatRequestDocumentsItem other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return this.value.toString(); + } + + public static V2ChatRequestDocumentsItem of(String value) { + return new V2ChatRequestDocumentsItem(value, 0); + } + + public static V2ChatRequestDocumentsItem of(Document value) { + return new V2ChatRequestDocumentsItem(value, 1); + } + + public interface Visitor { + T visit(String value); + + T visit(Document value); + } + + static final class Deserializer extends StdDeserializer { + Deserializer() { + super(V2ChatRequestDocumentsItem.class); + } + + @java.lang.Override + public V2ChatRequestDocumentsItem deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + Object value = p.readValueAs(Object.class); + try { + return of(ObjectMappers.JSON_MAPPER.convertValue(value, String.class)); + } catch (IllegalArgumentException e) { + } + try { + return of(ObjectMappers.JSON_MAPPER.convertValue(value, Document.class)); + } catch (IllegalArgumentException e) { + } + throw new JsonParseException(p, "Failed to deserialize"); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/V2ChatRequestSafetyMode.java b/src/main/java/com/cohere/api/resources/v2/types/V2ChatRequestSafetyMode.java new file mode 100644 index 0000000..1081e6a --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/V2ChatRequestSafetyMode.java @@ -0,0 +1,26 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum V2ChatRequestSafetyMode { + CONTEXTUAL("CONTEXTUAL"), + + STRICT("STRICT"), + + NONE("NONE"); + + private final String value; + + V2ChatRequestSafetyMode(String value) { + this.value = value; + } + + @JsonValue + @java.lang.Override + public String toString() { + return this.value; + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/V2ChatStreamRequestDocumentsItem.java b/src/main/java/com/cohere/api/resources/v2/types/V2ChatStreamRequestDocumentsItem.java new file mode 100644 index 0000000..39f2f61 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/V2ChatStreamRequestDocumentsItem.java @@ -0,0 +1,95 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.cohere.api.core.ObjectMappers; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import java.io.IOException; +import java.util.Objects; + +@JsonDeserialize(using = V2ChatStreamRequestDocumentsItem.Deserializer.class) +public final class V2ChatStreamRequestDocumentsItem { + private final Object value; + + private final int type; + + private V2ChatStreamRequestDocumentsItem(Object value, int type) { + this.value = value; + this.type = type; + } + + @JsonValue + public Object get() { + return this.value; + } + + public T visit(Visitor visitor) { + if (this.type == 0) { + return visitor.visit((String) this.value); + } else if (this.type == 1) { + return visitor.visit((Document) this.value); + } + throw new IllegalStateException("Failed to visit value. This should never happen."); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof V2ChatStreamRequestDocumentsItem && equalTo((V2ChatStreamRequestDocumentsItem) other); + } + + private boolean equalTo(V2ChatStreamRequestDocumentsItem other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return this.value.toString(); + } + + public static V2ChatStreamRequestDocumentsItem of(String value) { + return new V2ChatStreamRequestDocumentsItem(value, 0); + } + + public static V2ChatStreamRequestDocumentsItem of(Document value) { + return new V2ChatStreamRequestDocumentsItem(value, 1); + } + + public interface Visitor { + T visit(String value); + + T visit(Document value); + } + + static final class Deserializer extends StdDeserializer { + Deserializer() { + super(V2ChatStreamRequestDocumentsItem.class); + } + + @java.lang.Override + public V2ChatStreamRequestDocumentsItem deserialize(JsonParser p, DeserializationContext ctxt) + throws IOException { + Object value = p.readValueAs(Object.class); + try { + return of(ObjectMappers.JSON_MAPPER.convertValue(value, String.class)); + } catch (IllegalArgumentException e) { + } + try { + return of(ObjectMappers.JSON_MAPPER.convertValue(value, Document.class)); + } catch (IllegalArgumentException e) { + } + throw new JsonParseException(p, "Failed to deserialize"); + } + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/V2ChatStreamRequestSafetyMode.java b/src/main/java/com/cohere/api/resources/v2/types/V2ChatStreamRequestSafetyMode.java new file mode 100644 index 0000000..09caaeb --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/V2ChatStreamRequestSafetyMode.java @@ -0,0 +1,26 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonValue; + +public enum V2ChatStreamRequestSafetyMode { + CONTEXTUAL("CONTEXTUAL"), + + STRICT("STRICT"), + + NONE("NONE"); + + private final String value; + + V2ChatStreamRequestSafetyMode(String value) { + this.value = value; + } + + @JsonValue + @java.lang.Override + public String toString() { + return this.value; + } +} diff --git a/src/main/java/com/cohere/api/resources/v2/types/V2EmbedRequest.java b/src/main/java/com/cohere/api/resources/v2/types/V2EmbedRequest.java new file mode 100644 index 0000000..06fcf71 --- /dev/null +++ b/src/main/java/com/cohere/api/resources/v2/types/V2EmbedRequest.java @@ -0,0 +1,375 @@ +/** + * This file was auto-generated by Fern from our API Definition. + */ +package com.cohere.api.resources.v2.types; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.Objects; +import java.util.Optional; + +public final class V2EmbedRequest { + private final Value value; + + @JsonCreator(mode = JsonCreator.Mode.DELEGATING) + private V2EmbedRequest(Value value) { + this.value = value; + } + + public T visit(Visitor visitor) { + return value.visit(visitor); + } + + public static V2EmbedRequest searchDocument(Texts value) { + return new V2EmbedRequest(new SearchDocumentValue(value)); + } + + public static V2EmbedRequest searchQuery(Texts value) { + return new V2EmbedRequest(new SearchQueryValue(value)); + } + + public static V2EmbedRequest classification(Texts value) { + return new V2EmbedRequest(new ClassificationValue(value)); + } + + public static V2EmbedRequest clustering(Texts value) { + return new V2EmbedRequest(new ClusteringValue(value)); + } + + public static V2EmbedRequest image(Images value) { + return new V2EmbedRequest(new ImageValue(value)); + } + + public boolean isSearchDocument() { + return value instanceof SearchDocumentValue; + } + + public boolean isSearchQuery() { + return value instanceof SearchQueryValue; + } + + public boolean isClassification() { + return value instanceof ClassificationValue; + } + + public boolean isClustering() { + return value instanceof ClusteringValue; + } + + public boolean isImage() { + return value instanceof ImageValue; + } + + public boolean _isUnknown() { + return value instanceof _UnknownValue; + } + + public Optional getSearchDocument() { + if (isSearchDocument()) { + return Optional.of(((SearchDocumentValue) value).value); + } + return Optional.empty(); + } + + public Optional getSearchQuery() { + if (isSearchQuery()) { + return Optional.of(((SearchQueryValue) value).value); + } + return Optional.empty(); + } + + public Optional getClassification() { + if (isClassification()) { + return Optional.of(((ClassificationValue) value).value); + } + return Optional.empty(); + } + + public Optional getClustering() { + if (isClustering()) { + return Optional.of(((ClusteringValue) value).value); + } + return Optional.empty(); + } + + public Optional getImage() { + if (isImage()) { + return Optional.of(((ImageValue) value).value); + } + return Optional.empty(); + } + + public Optional _getUnknown() { + if (_isUnknown()) { + return Optional.of(((_UnknownValue) value).value); + } + return Optional.empty(); + } + + @JsonValue + private Value getValue() { + return this.value; + } + + public interface Visitor { + T visitSearchDocument(Texts searchDocument); + + T visitSearchQuery(Texts searchQuery); + + T visitClassification(Texts classification); + + T visitClustering(Texts clustering); + + T visitImage(Images image); + + T _visitUnknown(Object unknownType); + } + + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + property = "input_type", + visible = true, + defaultImpl = _UnknownValue.class) + @JsonSubTypes({ + @JsonSubTypes.Type(SearchDocumentValue.class), + @JsonSubTypes.Type(SearchQueryValue.class), + @JsonSubTypes.Type(ClassificationValue.class), + @JsonSubTypes.Type(ClusteringValue.class), + @JsonSubTypes.Type(ImageValue.class) + }) + @JsonIgnoreProperties(ignoreUnknown = true) + private interface Value { + T visit(Visitor visitor); + } + + @JsonTypeName("search_document") + private static final class SearchDocumentValue implements Value { + @JsonUnwrapped + private Texts value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private SearchDocumentValue() {} + + private SearchDocumentValue(Texts value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitSearchDocument(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof SearchDocumentValue && equalTo((SearchDocumentValue) other); + } + + private boolean equalTo(SearchDocumentValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "V2EmbedRequest{" + "value: " + value + "}"; + } + } + + @JsonTypeName("search_query") + private static final class SearchQueryValue implements Value { + @JsonUnwrapped + private Texts value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private SearchQueryValue() {} + + private SearchQueryValue(Texts value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitSearchQuery(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof SearchQueryValue && equalTo((SearchQueryValue) other); + } + + private boolean equalTo(SearchQueryValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "V2EmbedRequest{" + "value: " + value + "}"; + } + } + + @JsonTypeName("classification") + private static final class ClassificationValue implements Value { + @JsonUnwrapped + private Texts value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ClassificationValue() {} + + private ClassificationValue(Texts value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitClassification(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ClassificationValue && equalTo((ClassificationValue) other); + } + + private boolean equalTo(ClassificationValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "V2EmbedRequest{" + "value: " + value + "}"; + } + } + + @JsonTypeName("clustering") + private static final class ClusteringValue implements Value { + @JsonUnwrapped + private Texts value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ClusteringValue() {} + + private ClusteringValue(Texts value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitClustering(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ClusteringValue && equalTo((ClusteringValue) other); + } + + private boolean equalTo(ClusteringValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "V2EmbedRequest{" + "value: " + value + "}"; + } + } + + @JsonTypeName("image") + private static final class ImageValue implements Value { + @JsonUnwrapped + private Images value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private ImageValue() {} + + private ImageValue(Images value) { + this.value = value; + } + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor.visitImage(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof ImageValue && equalTo((ImageValue) other); + } + + private boolean equalTo(ImageValue other) { + return value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.value); + } + + @java.lang.Override + public String toString() { + return "V2EmbedRequest{" + "value: " + value + "}"; + } + } + + private static final class _UnknownValue implements Value { + private String type; + + @JsonValue + private Object value; + + @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + private _UnknownValue(@JsonProperty("value") Object value) {} + + @java.lang.Override + public T visit(Visitor visitor) { + return visitor._visitUnknown(value); + } + + @java.lang.Override + public boolean equals(Object other) { + if (this == other) return true; + return other instanceof _UnknownValue && equalTo((_UnknownValue) other); + } + + private boolean equalTo(_UnknownValue other) { + return type.equals(other.type) && value.equals(other.value); + } + + @java.lang.Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @java.lang.Override + public String toString() { + return "V2EmbedRequest{" + "type: " + type + ", value: " + value + "}"; + } + } +} diff --git a/src/main/java/com/cohere/api/types/EmbedInputType.java b/src/main/java/com/cohere/api/types/EmbedInputType.java index 0e507cf..305319a 100644 --- a/src/main/java/com/cohere/api/types/EmbedInputType.java +++ b/src/main/java/com/cohere/api/types/EmbedInputType.java @@ -12,7 +12,9 @@ public enum EmbedInputType { CLASSIFICATION("classification"), - CLUSTERING("clustering"); + CLUSTERING("clustering"), + + IMAGE("image"); private final String value;