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 Dec 22, 2023
1 parent 7fc98e8 commit 8e8daa1
Show file tree
Hide file tree
Showing 13 changed files with 1,394 additions and 46 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ publishing {
maven(MavenPublication) {
groupId = 'com.cohere'
artifactId = 'cohere-java'
version = '1.0.3'
version = '1.0.4'
from components.java
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/cohere/api/Cohere.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.cohere.api.requests.SummarizeRequest;
import com.cohere.api.requests.TokenizeRequest;
import com.cohere.api.resources.connectors.ConnectorsClient;
import com.cohere.api.resources.datasets.DatasetsClient;
import com.cohere.api.types.ClassifyResponse;
import com.cohere.api.types.DetectLanguageResponse;
import com.cohere.api.types.DetokenizeResponse;
Expand All @@ -42,10 +43,13 @@
public class Cohere {
protected final ClientOptions clientOptions;

protected final Supplier<DatasetsClient> datasetsClient;

protected final Supplier<ConnectorsClient> connectorsClient;

public Cohere(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
this.datasetsClient = Suppliers.memoize(() -> new DatasetsClient(clientOptions));
this.connectorsClient = Suppliers.memoize(() -> new ConnectorsClient(clientOptions));
}

Expand Down Expand Up @@ -480,6 +484,10 @@ public DetokenizeResponse detokenize(DetokenizeRequest request) {
return detokenize(request, null);
}

public DatasetsClient datasets() {
return this.datasetsClient.get();
}

public ConnectorsClient connectors() {
return this.connectorsClient.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 @@ -29,7 +29,7 @@ private ClientOptions(
"X-Fern-SDK-Name",
"com.cohere.fern:api-sdk",
"X-Fern-SDK-Version",
"1.0.3",
"1.0.4",
"X-Fern-Language",
"JAVA"));
this.headerSuppliers = headerSuppliers;
Expand Down
165 changes: 165 additions & 0 deletions src/main/java/com/cohere/api/resources/datasets/DatasetsClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.cohere.api.resources.datasets;

import com.cohere.api.core.ApiError;
import com.cohere.api.core.ClientOptions;
import com.cohere.api.core.ObjectMappers;
import com.cohere.api.core.RequestOptions;
import com.cohere.api.resources.datasets.requests.DatasetsListRequest;
import com.cohere.api.resources.datasets.types.DatasetsGetResponse;
import com.cohere.api.resources.datasets.types.DatasetsGetUsageResponse;
import com.cohere.api.resources.datasets.types.DatasetsListResponse;
import com.fasterxml.jackson.core.type.TypeReference;
import java.io.IOException;
import java.util.Map;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.Response;

public class DatasetsClient {
protected final ClientOptions clientOptions;

public DatasetsClient(ClientOptions clientOptions) {
this.clientOptions = clientOptions;
}

public DatasetsListResponse list() {
return list(DatasetsListRequest.builder().build());
}

public DatasetsListResponse list(DatasetsListRequest request, RequestOptions requestOptions) {
HttpUrl.Builder httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("dataset");
if (request.getDatasetType().isPresent()) {
httpUrl.addQueryParameter("datasetType", request.getDatasetType().get());
}
if (request.getBefore().isPresent()) {
httpUrl.addQueryParameter("before", request.getBefore().get().toString());
}
if (request.getAfter().isPresent()) {
httpUrl.addQueryParameter("after", request.getAfter().get().toString());
}
if (request.getLimit().isPresent()) {
httpUrl.addQueryParameter("limit", request.getLimit().get());
}
if (request.getOffset().isPresent()) {
httpUrl.addQueryParameter("offset", request.getOffset().get());
}
Request.Builder _requestBuilder = new Request.Builder()
.url(httpUrl.build())
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json");
Request okhttpRequest = _requestBuilder.build();
try {
Response response =
clientOptions.httpClient().newCall(okhttpRequest).execute();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), DatasetsListResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public DatasetsListResponse list(DatasetsListRequest request) {
return list(request, null);
}

public DatasetsGetUsageResponse getUsage(RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("dataset/usage")
.build();
Request okhttpRequest = new Request.Builder()
.url(httpUrl)
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.build();
try {
Response response =
clientOptions.httpClient().newCall(okhttpRequest).execute();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), DatasetsGetUsageResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public DatasetsGetUsageResponse getUsage() {
return getUsage(null);
}

public DatasetsGetResponse get(String id, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("dataset")
.addPathSegment(id)
.build();
Request okhttpRequest = new Request.Builder()
.url(httpUrl)
.method("GET", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.build();
try {
Response response =
clientOptions.httpClient().newCall(okhttpRequest).execute();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(response.body().string(), DatasetsGetResponse.class);
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public DatasetsGetResponse get(String id) {
return get(id, null);
}

public Map<String, Object> delete(String id, RequestOptions requestOptions) {
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl())
.newBuilder()
.addPathSegments("dataset")
.addPathSegment(id)
.build();
Request okhttpRequest = new Request.Builder()
.url(httpUrl)
.method("DELETE", null)
.headers(Headers.of(clientOptions.headers(requestOptions)))
.addHeader("Content-Type", "application/json")
.build();
try {
Response response =
clientOptions.httpClient().newCall(okhttpRequest).execute();
if (response.isSuccessful()) {
return ObjectMappers.JSON_MAPPER.readValue(
response.body().string(), new TypeReference<Map<String, Object>>() {});
}
throw new ApiError(
response.code(),
ObjectMappers.JSON_MAPPER.readValue(response.body().string(), Object.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public Map<String, Object> delete(String id) {
return delete(id, null);
}
}
Loading

0 comments on commit 8e8daa1

Please sign in to comment.