Skip to content

Commit

Permalink
SDK regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Sep 18, 2024
1 parent a236775 commit ae6d284
Show file tree
Hide file tree
Showing 8 changed files with 310 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
205 changes: 189 additions & 16 deletions src/main/java/com/cohere/api/Cohere.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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 Down Expand Up @@ -88,34 +90,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 +259,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 +612,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
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 ae6d284

Please sign in to comment.