The Phenoml Java library provides convenient access to the Phenoml API from Java.
Instantiate and use the client with the following:
package com.example.usage;
import com.phenoml.api.PhenomlClient;
import com.phenoml.api.resources.agent.types.AgentCreateRequest;
import java.util.ArrayList;
import java.util.Arrays;
public class Example {
public static void main(String[] args) {
PhenomlClient client = PhenomlClient.builder()
.clientId("YOUR_CLIENT_ID")
.clientSecret("YOUR_CLIENT_SECRET")
.url("https://yourinstance.app.pheno.ml")
.build();
client.agent().create(
AgentCreateRequest
.builder()
.name("name")
.provider(AgentCreateRequest.Provider.of("provider_id"))
.prompts(
new ArrayList<String>(
Arrays.asList("prompt_123", "prompt_456")
)
)
.build()
);
}
}This SDK allows you to configure different environments for API requests.
import com.phenoml.api.PhenomlClient;
import com.phenoml.api.core.Environment;
PhenomlClient client = PhenomlClient
.builder()
.environment(Environment.Default)
.build();You can set a custom base URL when constructing the client.
import com.phenoml.api.PhenomlClient;
PhenomlClient client = PhenomlClient
.builder()
.url("https://yourinstance.app.pheno.ml")
.build();When the API returns a non-success status code (4xx or 5xx response), an API exception will be thrown.
import com.phenoml.api.core.PhenomlClientApiException;
try {
client.agent().create(...);
} catch (PhenomlClientApiException e) {
// Do something with the API exception...
}This SDK is built to work with any instance of OkHttpClient. By default, if no client is provided, the SDK will construct one.
However, you can pass your own client like so:
import com.phenoml.api.PhenomlClient;
import okhttp3.OkHttpClient;
OkHttpClient customClient = ...;
PhenomlClient client = PhenomlClient
.builder()
.httpClient(customClient)
.build();The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
A request is deemed retryable when any of the following HTTP status codes is returned:
Use the maxRetries client option to configure this behavior.
import com.phenoml.api.PhenomlClient;
PhenomlClient client = PhenomlClient
.builder()
.maxRetries(1)
.build();The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
import com.phenoml.api.PhenomlClient;
import com.phenoml.api.core.RequestOptions;
// Client level
PhenomlClient client = PhenomlClient
.builder()
.timeout(10)
.build();
// Request level
client.agent().create(
...,
RequestOptions
.builder()
.timeout(10)
.build()
);While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!