Skip to content

Commit

Permalink
#10: Prepare snapshot 0.8.0.BETA-JDK11-SNAPSHOT for JDK 11 build (#15)
Browse files Browse the repository at this point in the history
* #10: Prepare snapshot 0.8.0.BETA-JDK11-SNAPSHOT for JDK 11 build

* #10: Prepare snapshot 0.8.0.BETA-JDK11-SNAPSHOT for JDK 11 build

* #10: Prepare snapshot 0.8.0.BETA-JDK11-SNAPSHOT for JDK 11 build

* #10: Apply code formatting

* #10: Apply code formatting

* #10: Actions and README.md updates

* #10: Additional improvements

* #10: Update build icon for JDK11
  • Loading branch information
yoanaborissova-cdx authored Jan 5, 2024
1 parent 27a92f0 commit 19a9840
Show file tree
Hide file tree
Showing 59 changed files with 3,360 additions and 393 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ name: Maven Build
on:
push:
branches:
- release/jdk-17
- release/jdk-11
pull_request:
branches:
- release/jdk-17
- release/jdk-11

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '17'
java-version: '11'
distribution: 'temurin'
- name: JaCoCo Coverage
run: mvn clean test jacoco:report -Pmvn-deploy
Expand Down
52 changes: 28 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<div align="center">

[![Maven Central](https://img.shields.io/maven-central/v/bg.codexio.ai/openai-api-sdk?versionSuffix=JDK17&color=EE5A9C)](https://central.sonatype.com/artifact/bg.codexio.ai/openai-api-sdk)
[![Maven Central](https://img.shields.io/maven-central/v/bg.codexio.ai/openai-api-sdk?versionSuffix=JDK11&color=EE5A9C)](https://central.sonatype.com/artifact/bg.codexio.ai/openai-api-sdk)
[![Build](https://github.com/CodexioLtd/openai-api-sdk/actions/workflows/maven.yml/badge.svg)](https://github.com/CodexioLtd/openai-api-sdk/actions/workflows/maven.yml)
[![Coverage](https://codecov.io/github/CodexioLtd/openai-api-sdk/graph/badge.svg?token=013OEUIYWI)](https://codecov.io/github/CodexioLtd/openai-api-sdk)
[![License](https://img.shields.io/github/license/CodexioLtd/openai-api-sdk.svg)](https://github.com/CodexioLtd/openai-api-sdk/blob/master/LICENSE)
Expand All @@ -21,7 +21,8 @@

## Preambule

This library provides a Software Development Kit (SDK) for Java 17<sup>([see others](#supported-java-versions))</sup> compliant runtimes
This library provides a Software Development Kit (SDK) for Java 11<sup>([see others](#supported-java-versions))</sup>
compliant runtimes
to connect to an OpenAI API and execute both synchronous and asynchronous (via callbacks
or the Reactor Pattern) calls.

Expand Down Expand Up @@ -117,10 +118,11 @@ In the next chapters you will see an explanation of all key concepts.
3. Add the library as a dependency in your project

```xml

<dependency>
<groupId>bg.codexio.ai</groupId>
<artifactId>openai-api-sdk</artifactId>
<version>0.8.0.BETA-JDK17</version>
<version>0.8.0.BETA-JDK11</version>
</dependency>
```

Expand All @@ -131,14 +133,14 @@ In the next chapters you will see an explanation of all key concepts.
<summary>
Click here to see
</summary>
| Artifact | Description |
|-----------------------|---------------------------------------------------------------------------------------------------|
| `openai-api-models` | Contains info only for AI Model namings, such as GPT-4-Preview, DALL-E-2 and so on |
| `openai-api-payload` | Contains Request/Response DTO models and related information |
| `openai-api-http` | Contains HTTP Clients such as `ChatHttpExecutor`, `CreateImageHttpExecutor`, etc., ... |
| `openai-api-examples` | Usually you do not import this artfiactId, rather you can check the source code for some examples |

| Artifact | Description |
|-----------------------|---------------------------------------------------------------------------------------------------|
| `openai-api-models` | Contains info only for AI Model namings, such as GPT-4-Preview, DALL-E-2 and so on |
| `openai-api-payload` | Contains Request/Response DTO models and related information |
| `openai-api-http` | Contains HTTP Clients such as `ChatHttpExecutor`, `CreateImageHttpExecutor`, etc., ... |
| `openai-api-examples` | Usually you do not import this artfiactId, rather you can check the source code for some examples |

</details>

4. Create in your `src/main/resources` folder a file named `openai-credentials.json` with the following content:
Expand Down Expand Up @@ -264,7 +266,7 @@ Java, you make every byte worthwhile.

## Supported Java Versions

The `master` branch builds versions for JDK 21. This is the current Java version and the artifacts built from
The `master` branch builds versions for JDK 21. This is the current Java version and the artifacts built from
`master` does not contain any JDK suffix. However, there are several other branches which build versions
for different JDKs. See the table below:

Expand All @@ -275,7 +277,6 @@ for different JDKs. See the table below:
| [release/jdk-11](https://github.com/CodexioLtd/openai-api-sdk/tree/release/jdk-11) | 11 | X.Y.Z[.a]-JDK11 (e.g. 0.8.0.BETA-JDK11) |
| [release/jdk-8](https://github.com/CodexioLtd/openai-api-sdk/tree/release/jdk-8) | 8 | X.Y.Z[.a]-JDK8 (e.g. 0.8.0.BETA-JDK8) |


## Available SDKs

### List
Expand Down Expand Up @@ -346,11 +347,15 @@ Credentials are passed to the SDK via instantiating the `openai-api-payload/ApiC
object, which looks like:

```java
public record ApiCredentials(
String apiKey,
String organization,
String baseUrl
) {}
public final class ApiCredentials {

public static final String BASE_URL = "https://api.openai.com/v1";
private final String apiKey;
private final String organization;
private final String baseUrl;

// constructor and getters here
}
```

Where `organization` and `baseUrl` are not mandatory, it will fall back to no specific
Expand Down Expand Up @@ -552,7 +557,7 @@ public class Main {
callbacks. Most of the APIs support two subscription promises - one for a stringified line of
the response (not recommended, but gives a lot of control if necessary) and another for
the whole response. Usually with `async().method().onEachLine(line -> { ... })` and
`async().method().thne(response -> { ... })`.
`async().method().thne(response -> { ... })`.
- `reactive()` - mostly the same as `async()`, but utilizes the `Mono<T>` and `Flux<T>`
patterns from Project Reactor. **This is only recommended if your codebase is already
fully reactive, using something like `Reactor Netty`**. Otherwise, the overhead of
Expand Down Expand Up @@ -924,13 +929,12 @@ public class GetNearbyPlaces
);
}

public record GetNearbyPlacesFunctionChoice()
public static final class GetNearbyPlacesFunctionChoice
implements FunctionChoice {
@Override
public String name() {
return GetNearbyPlaces.FUNCTION.function()
.getName();
public GetNearbyPlacesFunctionChoice() {
}

// constructor and getters here
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions openai-api-coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>bg.codexio.ai</groupId>
<artifactId>openai-api</artifactId>
<version>0.8.0.BETA-JDK17</version>
<version>0.8.0.BETA-JDK11-SNAPSHOT</version>
</parent>

<artifactId>openai-api-coverage</artifactId>
Expand All @@ -15,7 +15,7 @@
<description>Codexio Ltd. Open AI API SDK Test Coverage Aggregate Module</description>

<properties>
<internal.modules.version>0.8.0.BETA-JDK17</internal.modules.version>
<internal.modules.version>0.8.0.BETA-JDK11-SNAPSHOT</internal.modules.version>
<skipDeploy>false</skipDeploy>
</properties>

Expand Down
4 changes: 2 additions & 2 deletions openai-api-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>bg.codexio.ai</groupId>
<artifactId>openai-api</artifactId>
<version>0.8.0.BETA-JDK17</version>
<version>0.8.0.BETA-JDK11-SNAPSHOT</version>
</parent>

<artifactId>openai-api-examples</artifactId>
Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>bg.codexio.ai</groupId>
<artifactId>openai-api-sdk</artifactId>
<version>0.8.0.BETA-JDK17</version>
<version>0.8.0.BETA-JDK11-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
6 changes: 3 additions & 3 deletions openai-api-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>bg.codexio.ai</groupId>
<artifactId>openai-api</artifactId>
<version>0.8.0.BETA-JDK17</version>
<version>0.8.0.BETA-JDK11-SNAPSHOT</version>
</parent>

<artifactId>openai-api-http</artifactId>
Expand All @@ -22,13 +22,13 @@
<dependency>
<groupId>bg.codexio.ai</groupId>
<artifactId>openai-api-models</artifactId>
<version>0.8.0.BETA-JDK17</version>
<version>0.8.0.BETA-JDK11-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>bg.codexio.ai</groupId>
<artifactId>openai-api-payload</artifactId>
<version>0.8.0.BETA-JDK17</version>
<version>0.8.0.BETA-JDK11-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@

import bg.codexio.ai.openai.api.payload.credentials.ApiCredentials;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
* Context object holding authentication
* and timeout configuration
*
* @param credentials
* @param timeouts
*/
public record HttpExecutorContext(
ApiCredentials credentials,
HttpTimeouts timeouts
) {
public final class HttpExecutorContext {
private final ApiCredentials credentials;
private final HttpTimeouts timeouts;

/**
* @param credentials
* @param timeouts
*/
public HttpExecutorContext(
ApiCredentials credentials,
HttpTimeouts timeouts
) {
this.credentials = credentials;
this.timeouts = timeouts;
}

/**
* Constructing the object with default timeouts.
Expand Down Expand Up @@ -96,4 +105,45 @@ public HttpExecutorContext withReadTimeout(
)
);
}

public ApiCredentials credentials() {
return credentials;
}

public HttpTimeouts timeouts() {
return timeouts;
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || obj.getClass() != this.getClass()) {
return false;
}
var that = (HttpExecutorContext) obj;
return Objects.equals(
this.credentials,
that.credentials
) && Objects.equals(
this.timeouts,
that.timeouts
);
}

@Override
public int hashCode() {
return Objects.hash(
credentials,
timeouts
);
}

@Override
public String toString() {
return "HttpExecutorContext[" + "credentials=" + credentials + ", "
+ "timeouts=" + timeouts + ']';
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
package bg.codexio.ai.openai.api.http;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
* Representation of an HTTP Timeout.
* Can be used for all call, connect and read.
*/
public record HttpTimeout(
long period,
TimeUnit timeUnit
) {}
public final class HttpTimeout {
private final long period;
private final TimeUnit timeUnit;

public HttpTimeout(
long period,
TimeUnit timeUnit
) {
this.period = period;
this.timeUnit = timeUnit;
}

public long period() {
return period;
}

public TimeUnit timeUnit() {
return timeUnit;
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || obj.getClass() != this.getClass()) {
return false;
}
var that = (HttpTimeout) obj;
return this.period == that.period && Objects.equals(
this.timeUnit,
that.timeUnit
);
}

@Override
public int hashCode() {
return Objects.hash(
period,
timeUnit
);
}

@Override
public String toString() {
return "HttpTimeout[" + "period=" + period + ", " + "timeUnit="
+ timeUnit + ']';
}
}
Loading

0 comments on commit 19a9840

Please sign in to comment.