Skip to content

Commit

Permalink
🌿 Fern Regeneration -- May 8, 2024 (#17)
Browse files Browse the repository at this point in the history
* SDK regeneration

* clientName != null

---------

Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com>
Co-authored-by: Billy Trend <[email protected]>
  • Loading branch information
fern-api[bot] and billytrend-cohere authored May 8, 2024
1 parent a051b83 commit 3f6a079
Show file tree
Hide file tree
Showing 18 changed files with 278 additions and 171 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.0.5'
version = '1.0.6'
from components.java
pom {
name = 'cohere'
Expand Down
68 changes: 45 additions & 23 deletions src/main/java/com/cohere/api/Cohere.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;

public class Cohere {
protected final ClientOptions clientOptions;
Expand Down Expand Up @@ -103,13 +104,14 @@ public Iterable<StreamedChatResponse> chatStream(ChatStreamRequest request, Requ
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return new Stream<StreamedChatResponse>(
StreamedChatResponse.class, response.body().charStream(), "\n");
return new Stream<StreamedChatResponse>(StreamedChatResponse.class, responseBody.charStream(), "\n");
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -151,12 +153,14 @@ public NonStreamedChatResponse chat(ChatRequest request, RequestOptions requestO
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), NonStreamedChatResponse.class);
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), NonStreamedChatResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -205,13 +209,15 @@ public Iterable<GenerateStreamedResponse> generateStream(
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return new Stream<GenerateStreamedResponse>(
GenerateStreamedResponse.class, response.body().charStream(), "\n");
GenerateStreamedResponse.class, responseBody.charStream(), "\n");
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -259,12 +265,14 @@ public Generation generate(GenerateRequest request, RequestOptions requestOption
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Generation.class);
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), Generation.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -308,12 +316,14 @@ public EmbedResponse embed(EmbedRequest request, RequestOptions requestOptions)
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), EmbedResponse.class);
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), EmbedResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -353,12 +363,14 @@ public RerankResponse rerank(RerankRequest request, RequestOptions requestOption
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), RerankResponse.class);
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), RerankResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -400,12 +412,14 @@ public ClassifyResponse classify(ClassifyRequest request, RequestOptions request
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), ClassifyResponse.class);
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), ClassifyResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -453,12 +467,14 @@ public SummarizeResponse summarize(SummarizeRequest request, RequestOptions requ
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), SummarizeResponse.class);
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), SummarizeResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -498,12 +514,14 @@ public TokenizeResponse tokenize(TokenizeRequest request, RequestOptions request
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), TokenizeResponse.class);
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), TokenizeResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -543,12 +561,14 @@ public DetokenizeResponse detokenize(DetokenizeRequest request, RequestOptions r
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), DetokenizeResponse.class);
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), DetokenizeResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -581,12 +601,14 @@ public CheckApiKeyResponse checkApiKey(RequestOptions requestOptions) {
client = clientOptions.httpClientWithTimeout(requestOptions);
}
Response response = client.newCall(okhttpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), CheckApiKeyResponse.class);
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), CheckApiKeyResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
ObjectMappers.JSON_MAPPER.readValue(
responseBody != null ? responseBody.string() : "{}", Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/cohere/api/CohereBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public Cohere build() {
throw new RuntimeException("Please provide token or set the CO_API_KEY environment variable.");
}
this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token);
this.clientOptionsBuilder.addHeader("X-Client-Name", this.clientName);
if (clientName != null) {
this.clientOptionsBuilder.addHeader("X-Client-Name", this.clientName);
}
clientOptionsBuilder.environment(this.environment);
return new Cohere(clientOptionsBuilder.build());
}
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(
"X-Fern-SDK-Name",
"com.cohere.fern:api-sdk",
"X-Fern-SDK-Version",
"1.0.5",
"1.0.6",
"X-Fern-Language",
"JAVA"));
this.headerSuppliers = headerSuppliers;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/cohere/api/requests/ChatRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ public Optional<String> getModel() {
return model;
}

/**
* @return Defaults to <code>false</code>.
* <p>When <code>true</code>, the response will be a JSON stream of events. The final event will contain the complete response, and will have an <code>event_type</code> of <code>&quot;stream-end&quot;</code>.</p>
* <p>Streaming is beneficial for user interfaces that render the contents of the response piece by piece, as it gets generated.
* Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments</p>
*/
@JsonProperty("stream")
public Boolean getStream() {
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/cohere/api/requests/ChatStreamRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ public Optional<String> getModel() {
return model;
}

/**
* @return Defaults to <code>false</code>.
* <p>When <code>true</code>, the response will be a JSON stream of events. The final event will contain the complete response, and will have an <code>event_type</code> of <code>&quot;stream-end&quot;</code>.</p>
* <p>Streaming is beneficial for user interfaces that render the contents of the response piece by piece, as it gets generated.
* Compatible Deployments: Cohere Platform, Azure, AWS Sagemaker, Private Deployments</p>
*/
@JsonProperty("stream")
public Boolean getStream() {
return true;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/cohere/api/requests/GenerateRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ public Optional<Integer> getNumGenerations() {
return numGenerations;
}

/**
* @return When <code>true</code>, the response will be a JSON stream of events. Streaming is beneficial for user interfaces that render the contents of the response piece by piece, as it gets generated.
* <p>The final event will contain the complete response, and will contain an <code>is_finished</code> field set to <code>true</code>. The event will also contain a <code>finish_reason</code>, which can be one of the following:</p>
* <ul>
* <li><code>COMPLETE</code> - the model sent back a finished reply</li>
* <li><code>MAX_TOKENS</code> - the reply was cut off because the model reached the maximum number of tokens for its context length</li>
* <li><code>ERROR</code> - something went wrong when generating the reply</li>
* <li><code>ERROR_TOXIC</code> - the model generated a reply that was deemed toxic</li>
* </ul>
*/
@JsonProperty("stream")
public Boolean getStream() {
return false;
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/cohere/api/requests/GenerateStreamRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ public Optional<Integer> getNumGenerations() {
return numGenerations;
}

/**
* @return When <code>true</code>, the response will be a JSON stream of events. Streaming is beneficial for user interfaces that render the contents of the response piece by piece, as it gets generated.
* <p>The final event will contain the complete response, and will contain an <code>is_finished</code> field set to <code>true</code>. The event will also contain a <code>finish_reason</code>, which can be one of the following:</p>
* <ul>
* <li><code>COMPLETE</code> - the model sent back a finished reply</li>
* <li><code>MAX_TOKENS</code> - the reply was cut off because the model reached the maximum number of tokens for its context length</li>
* <li><code>ERROR</code> - something went wrong when generating the reply</li>
* <li><code>ERROR_TOXIC</code> - the model generated a reply that was deemed toxic</li>
* </ul>
*/
@JsonProperty("stream")
public Boolean getStream() {
return true;
Expand Down
Loading

0 comments on commit 3f6a079

Please sign in to comment.