Skip to content

Commit

Permalink
SDK regeneration (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
  • Loading branch information
fern-api[bot] committed Sep 19, 2024
1 parent a236775 commit 1cccf8c
Show file tree
Hide file tree
Showing 87 changed files with 11,952 additions and 36 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
213 changes: 197 additions & 16 deletions src/main/java/com/cohere/api/Cohere.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -67,6 +70,8 @@
public class Cohere {
protected final ClientOptions clientOptions;

protected final Supplier<V2Client> v2Client;

protected final Supplier<EmbedJobsClient> embedJobsClient;

protected final Supplier<DatasetsClient> datasetsClient;
Expand All @@ -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));
Expand All @@ -88,34 +94,115 @@ 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 <a href="https://docs.cohere.com/docs/chat-api">Text Generation guides</a>.
* To learn how to use the Chat API and RAG follow our <a href="https://docs.cohere.com/docs/chat-api">Text Generation guides</a>.
*/
public Iterable<StreamedChatResponse> chatStream(ChatStreamRequest request) {
return chatStream(request, null);
}

/**
* Generates a text response to a user message.
* To learn how to use the Chat API with Streaming and RAG follow our <a href="https://docs.cohere.com/docs/chat-api">Text Generation guides</a>.
* To learn how to use the Chat API and RAG follow our <a href="https://docs.cohere.com/docs/chat-api">Text Generation guides</a>.
*/
public Iterable<StreamedChatResponse> chatStream(ChatStreamRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v1/chat")
.build();
Map<String, Object> 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);
Expand Down Expand Up @@ -176,34 +263,115 @@ public Iterable<StreamedChatResponse> 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 <a href="https://docs.cohere.com/docs/chat-api">Text Generation guides</a>.
* To learn how to use the Chat API and RAG follow our <a href="https://docs.cohere.com/docs/chat-api">Text Generation guides</a>.
*/
public NonStreamedChatResponse chat(ChatRequest request) {
return chat(request, null);
}

/**
* Generates a text response to a user message.
* To learn how to use the Chat API with Streaming and RAG follow our <a href="https://docs.cohere.com/docs/chat-api">Text Generation guides</a>.
* To learn how to use the Chat API and RAG follow our <a href="https://docs.cohere.com/docs/chat-api">Text Generation guides</a>.
*/
public NonStreamedChatResponse chat(ChatRequest request, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("v1/chat")
.build();
Map<String, Object> 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);
Expand Down Expand Up @@ -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.
* <p>Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.</p>
* <p>If you want to learn more how to use the embedding model, have a look at the <a href="/docs/semantic-search">Semantic Search Guide</a>.</p>
*/
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.
* <p>Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.</p>
Expand Down Expand Up @@ -1055,6 +1232,10 @@ public CheckApiKeyResponse checkApiKey(RequestOptions requestOptions) {
}
}

public V2Client v2() {
return this.v2Client.get();
}

public EmbedJobsClient embedJobs() {
return this.embedJobsClient.get();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cohere/api/core/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 1cccf8c

Please sign in to comment.