Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌿 Fern Regeneration -- April 17, 2024 #13

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ jobs:

- name: Publish to maven
run: |
./.publish/prepare.sh
./gradlew publish
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
MAVEN_PUBLISH_REGISTRY_URL: "https://s01.oss.sonatype.org/content/repositories/releases/"
MAVEN_PUBLISH_REGISTRY_URL: "https://s01.oss.sonatype.org/content/repositories/releases/"
MAVEN_SIGNATURE_KID: ${{ secrets.MAVEN_SIGNATURE_KID }}
MAVEN_SIGNATURE_SECRET_KEY: ${{ secrets.MAVEN_SIGNATURE_SECRET_KEY }}
MAVEN_SIGNATURE_PASSWORD: ${{ secrets.MAVEN_SIGNATURE_PASSWORD }}
8 changes: 8 additions & 0 deletions .publish/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Write key ring file
echo "$MAVEN_SIGNATURE_SECRET_KEY" > armored_key.asc
gpg -o publish_key.gpg --dearmor armored_key.asc

# Generate gradle.properties file
echo "signing.keyId=$MAVEN_SIGNATURE_KID" > gradle.properties
echo "signing.secretKeyRingFile=publish_key.gpg" >> gradle.properties
echo "signing.password=$MAVEN_SIGNATURE_PASSWORD" >> gradle.properties
26 changes: 23 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ plugins {
id 'java-library'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.11.0'
id 'signing'
}

repositories {
mavenCentral()
maven {
url 'https://s01.oss.sonatype.org/content/repositories/releases/'
url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}
}

dependencies {
api 'com.squareup.okhttp3:okhttp:4.9.3'
api 'com.squareup.okhttp3:okhttp:4.12.0'
api 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
api 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.3'
api 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.3'
Expand All @@ -35,6 +36,9 @@ java {
withJavadocJar()
}

signing {
sign(publishing.publications)
}
test {
useJUnitPlatform()
testLogging {
Expand All @@ -46,8 +50,24 @@ publishing {
maven(MavenPublication) {
groupId = 'com.cohere'
artifactId = 'cohere-java'
version = '1.0.3'
version = '1.0.4'
from components.java
pom {
name = 'cohere'
description = 'The official SDK of cohere'
url = 'https://buildwithfern.com'
developers {
developer {
name = 'cohere'
email = '[email protected]'
}
}
scm {
connection = 'scm:git:git://github.com/cohere-ai/cohere-java.git'
developerConnection = 'scm:git:git://github.com/cohere-ai/cohere-java.git'
url = 'https://github.com/cohere-ai/cohere-java'
}
}
}
}
repositories {
Expand Down
Empty file added gradle.properties
Empty file.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
257 changes: 173 additions & 84 deletions src/main/java/com/cohere/api/Cohere.java

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion src/main/java/com/cohere/api/CohereBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@
public final class CohereBuilder {
private ClientOptions.Builder clientOptionsBuilder = ClientOptions.builder();

private String token = System.getenv("CO_API_KEY");

private String clientName = null;

private Environment environment = Environment.PRODUCTION;

/**
* Sets token.
* Defaults to the CO_API_KEY environment variable.
*/
public CohereBuilder token(String token) {
this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + token);
this.token = token;
return this;
}

/**
* Sets clientName
*/
public CohereBuilder clientName(String clientName) {
this.clientName = clientName;
return this;
}

Expand All @@ -27,6 +43,14 @@ public CohereBuilder url(String url) {
}

public Cohere build() {
if (token == null) {
throw new RuntimeException("Please provide token or set the CO_API_KEY environment variable.");
}
this.clientOptionsBuilder.addHeader("Authorization", "Bearer " + this.token);
if (clientName == null) {
throw new RuntimeException("Please provide clientName");
}
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/ApiError.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Object body() {
return this.body;
}

@Override
@java.lang.Override
public String toString() {
return "ApiError{" + "statusCode: " + statusCode + ", body: " + body + "}";
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/cohere/api/core/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import okhttp3.OkHttpClient;

Expand All @@ -29,7 +30,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 All @@ -56,6 +57,19 @@ public OkHttpClient httpClient() {
return this.httpClient;
}

public OkHttpClient httpClientWithTimeout(RequestOptions requestOptions) {
if (requestOptions == null) {
return this.httpClient;
}
return this.httpClient
.newBuilder()
.callTimeout(requestOptions.getTimeout().get(), requestOptions.getTimeoutTimeUnit())
.connectTimeout(0, TimeUnit.SECONDS)
.writeTimeout(0, TimeUnit.SECONDS)
.readTimeout(0, TimeUnit.SECONDS)
.build();
}

public static Builder builder() {
return new Builder();
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/cohere/api/core/MediaTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.cohere.api.core;

import okhttp3.MediaType;

public final class MediaTypes {

public static final MediaType APPLICATION_JSON = MediaType.parse("application/json");

private MediaTypes() {}
}
48 changes: 46 additions & 2 deletions src/main/java/com/cohere/api/core/RequestOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,41 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

public final class RequestOptions {
private final String token;

private RequestOptions(String token) {
private final String clientName;

private final Optional<Integer> timeout;

private final TimeUnit timeoutTimeUnit;

private RequestOptions(String token, String clientName, Optional<Integer> timeout, TimeUnit timeoutTimeUnit) {
this.token = token;
this.clientName = clientName;
this.timeout = timeout;
this.timeoutTimeUnit = timeoutTimeUnit;
}

public Optional<Integer> getTimeout() {
return timeout;
}

public TimeUnit getTimeoutTimeUnit() {
return timeoutTimeUnit;
}

public Map<String, String> getHeaders() {
Map<String, String> headers = new HashMap<>();
if (this.token != null) {
headers.put("Authorization", "Bearer " + this.token);
}
if (this.clientName != null) {
headers.put("X-Client-Name", this.clientName);
}
return headers;
}

Expand All @@ -28,13 +50,35 @@ public static Builder builder() {
public static final class Builder {
private String token = null;

private String clientName = null;

private Optional<Integer> timeout = null;

private TimeUnit timeoutTimeUnit = TimeUnit.SECONDS;

public Builder token(String token) {
this.token = token;
return this;
}

public Builder clientName(String clientName) {
this.clientName = clientName;
return this;
}

public Builder timeout(Integer timeout) {
this.timeout = Optional.of(timeout);
return this;
}

public Builder timeout(Integer timeout, TimeUnit timeoutTimeUnit) {
this.timeout = Optional.of(timeout);
this.timeoutTimeUnit = timeoutTimeUnit;
return this;
}

public RequestOptions build() {
return new RequestOptions(token);
return new RequestOptions(token, clientName, timeout, timeoutTimeUnit);
}
}
}
Loading
Loading