Skip to content

Commit

Permalink
feat: updates
Browse files Browse the repository at this point in the history
chore: unknown commit message
  • Loading branch information
stainless-bot authored and Stainless Bot committed Jul 17, 2024
1 parent af9f9a2 commit 303b5f2
Show file tree
Hide file tree
Showing 110 changed files with 16,639 additions and 118 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- main
- next

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1
configured_endpoints: 20
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-27d8d6da893c1cdd53b491ec05153df22b1e113965f253a1d6eb8d75b628173f.yml
91 changes: 90 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The OpenAI Java SDK is similar to the OpenAI Kotlin SDK but with minor differenc

## Documentation

The REST API documentation can be found [on platform.openai.com](https://platform.openai.com/docs).
The REST API documentation can be found on [platform.openai.com](https://platform.openai.com/docs).

---

Expand Down Expand Up @@ -83,6 +83,40 @@ ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
ChatCompletion chatCompletion = client.chat().completions().create(params);
```

### Example: listing resources

The OpenAI API provides a `list` method to get a paginated list of jobs.
You can retrieve the first page by:

```java
import com.openai.models.FineTuningJob;
import com.openai.models.Page;

FineTuningJobListPage page = client.fineTuning().jobs().list();
for (FineTuningJob job : page.data()) {
System.out.println(job);
}
```

Use the `FineTuningJobListParams` builder to set parameters:

```java
FineTuningJobListParams params = FineTuningJobListParams.builder()
.limit(20)
.build();
FineTuningJobListPage page1 = client.fineTuning().jobs().list(params);

// Using the `from` method of the builder you can reuse previous params values:
FineTuningJobListPage page2 = client.fineTuning().jobs().list(FineTuningJobListParams.builder()
.from(params)
.build());

// Or easily get params for the next page by using the helper `getNextPageParams`:
FineTuningJobListPage page3 = client.fineTuning().jobs().list(params.getNextPageParams(page2));
```

See [Pagination](#pagination) below for more information on transparently working with lists of objects without worrying about fetching each page.

---

## Requests
Expand Down Expand Up @@ -146,6 +180,57 @@ JsonValue secret = chatCompletion._additionalProperties().get("secret_field");

---

## Pagination

For methods that return a paginated list of results, this library provides convenient ways access
the results either one page at a time, or item-by-item across all pages.

### Auto-pagination

To iterate through all results across all pages, you can use `autoPager`,
which automatically handles fetching more pages for you:

### Synchronous

```java
// As an Iterable:
FineTuningJobListPage page = client.fineTuning().jobs().list(params);
for (FineTuningJob job : page.autoPager()) {
System.out.println(job);
};

// As a Stream:
client.fineTuning().jobs().list(params).autoPager().stream()
.limit(50)
.forEach(job -> System.out.println(job));
```

### Asynchronous

```java
// Using forEach, which returns CompletableFuture<Void>:
asyncClient.fineTuning().jobs().list(params).autoPager()
.forEach(job -> System.out.println(job), executor);
```

### Manual pagination

If none of the above helpers meet your needs, you can also manually request pages one-by-one.
A page of results has a `data()` method to fetch the list of objects, as well as top-level
`response` and other methods to fetch top-level data about the page. It also has methods
`hasNextPage`, `getNextPage`, and `getNextPageParams` methods to help with pagination.

```java
FineTuningJobListPage page = client.fineTuning().jobs().list(params);
while (page != null) {
for (FineTuningJob job : page.data()) {
System.out.println(job);
}

page = page.getNextPage().orElse(null);
}
```

---

## Error handling
Expand Down Expand Up @@ -244,3 +329,7 @@ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) con
We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.

We are keen for your feedback; please open an [issue](https://www.github.com/stainless-sdks/openai-java/issues) with questions, bugs, or suggestions.

## Requirements

This library requires Java 8 or later.
10 changes: 10 additions & 0 deletions openai-java-core/src/main/kotlin/com/openai/client/OpenAIClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ interface OpenAIClient {
fun async(): OpenAIClientAsync

fun chat(): ChatService

fun files(): FileService

fun moderations(): ModerationService

fun models(): ModelService

fun fineTuning(): FineTuningService

fun batches(): BatchService
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ interface OpenAIClientAsync {
fun sync(): OpenAIClient

fun chat(): ChatServiceAsync

fun files(): FileServiceAsync

fun moderations(): ModerationServiceAsync

fun models(): ModelServiceAsync

fun fineTuning(): FineTuningServiceAsync

fun batches(): BatchServiceAsync
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,31 @@ constructor(

private val chat: ChatServiceAsync by lazy { ChatServiceAsyncImpl(clientOptions) }

private val files: FileServiceAsync by lazy { FileServiceAsyncImpl(clientOptions) }

private val moderations: ModerationServiceAsync by lazy {
ModerationServiceAsyncImpl(clientOptions)
}

private val models: ModelServiceAsync by lazy { ModelServiceAsyncImpl(clientOptions) }

private val fineTuning: FineTuningServiceAsync by lazy {
FineTuningServiceAsyncImpl(clientOptions)
}

private val batches: BatchServiceAsync by lazy { BatchServiceAsyncImpl(clientOptions) }

override fun sync(): OpenAIClient = sync

override fun chat(): ChatServiceAsync = chat

override fun files(): FileServiceAsync = files

override fun moderations(): ModerationServiceAsync = moderations

override fun models(): ModelServiceAsync = models

override fun fineTuning(): FineTuningServiceAsync = fineTuning

override fun batches(): BatchServiceAsync = batches
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,27 @@ constructor(

private val chat: ChatService by lazy { ChatServiceImpl(clientOptions) }

private val files: FileService by lazy { FileServiceImpl(clientOptions) }

private val moderations: ModerationService by lazy { ModerationServiceImpl(clientOptions) }

private val models: ModelService by lazy { ModelServiceImpl(clientOptions) }

private val fineTuning: FineTuningService by lazy { FineTuningServiceImpl(clientOptions) }

private val batches: BatchService by lazy { BatchServiceImpl(clientOptions) }

override fun async(): OpenAIClientAsync = async

override fun chat(): ChatService = chat

override fun files(): FileService = files

override fun moderations(): ModerationService = moderations

override fun models(): ModelService = models

override fun fineTuning(): FineTuningService = fineTuning

override fun batches(): BatchService = batches
}
Loading

0 comments on commit 303b5f2

Please sign in to comment.