Skip to content

Commit 7537e5e

Browse files
authored
update readme layout & added badges
1 parent 95b05ac commit 7537e5e

File tree

1 file changed

+90
-60
lines changed

1 file changed

+90
-60
lines changed

README.md

Lines changed: 90 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
11
# OpenAI For Java
2-
[![codecov](https://codecov.io/gh/jetkai/openai-for-java/branch/main/graph/badge.svg?token=2E96DBLLN0)](https://codecov.io/gh/jetkai/openai-for-java)
2+
3+
![GitHub last commit](https://img.shields.io/github/last-commit/jetkai/openai-for-java)
34
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/jetkai/openai-for-java/main.yml)
4-
5-
###### OpenAI API Reference -> https://platform.openai.com/docs/api-reference/
6-
###### OpenAI API Key -> https://platform.openai.com/account/api-keys
5+
![GitHub tag checks state](https://img.shields.io/github/checks-status/jetkai/openai-for-java/1.1.0)
6+
![GitHub deployments](https://img.shields.io/github/deployments/jetkai/openai-for-java/openai-for-java?label=deployment)
7+
[![codecov](https://codecov.io/gh/jetkai/openai-for-java/branch/main/graph/badge.svg?token=2E96DBLLN0)](https://codecov.io/gh/jetkai/openai-for-java)
8+
![GitHub issues](https://img.shields.io/github/issues/jetkai/openai-for-java)
9+
![GitHub all releases](https://img.shields.io/github/downloads/jetkai/openai-for-java/total)
10+
11+
> Note, this project is under active development. If there are any suggestions you may have, feel free to let me know. 😊
12+
>
13+
> You can use this library as part of your project & integrate it into your app.
14+
>
15+
> OpenAI is **free-to-use**, but you will require an API key. You can get this for free by clicking [**here**](https://platform.openai.com/account/api-keys).
16+
17+
```java
18+
OpenAI openAI = OpenAI.builder()
19+
.setApiKey("YOUR_API_KEY_HERE") //Required
20+
.setOrganization("YOUR_ORGANIZATION_HERE") //Optional
21+
.createChatCompletion(chatMessageHistoryHere) //Optional (ChatGPT)
22+
.setTimeout(Duration.ofSeconds(10)) //Optional
23+
.setProxy(proxy) //Optional
24+
.build() //Creates our OpenAI class from our OpenAI.Builder
25+
.sendRequest(); //Optional - Sends request to OpenAI
26+
```
27+
28+
---
29+
30+
## Minimum Requirements
31+
32+
- Java 11 [JDK](https://developers.redhat.com/content-gateway/file/openjdk/11.0.18/java-11-openjdk-11.0.18.10-1.windows.redhat.x86_64.msi)
33+
- An OpenAI [API Key](https://platform.openai.com/account/api-keys)
734

835
## Release `1.1.0`
936

37+
> The dependencies I am using for this project are [`jackson-databind`](https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind) for JSON parsing, [`junit-jupiter`](https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api) for testing and [`jacoco`](https://mvnrepository.com/artifact/org.jacoco/jacoco-maven-plugin) for reporting.
38+
1039
```xml
1140
<dependency>
1241
<groupId>io.github.jetkai</groupId>
@@ -15,19 +44,26 @@
1544
</dependency>
1645
```
1746

18-
#### Binary:
19-
- [openai.jar](https://github.com/jetkai/openai-for-java/releases/download/1.1.0/openai.jar) `(with dependencies)`
20-
- [openai-excldeps.jar](https://github.com/jetkai/openai-for-java/releases/download/1.1.0/openai-excldeps.jar) `(excluding dependencies)`
47+
| Binary `(Recommended)` | Binary `(Excluding Dependencies)` | JavaDoc | Sources |
48+
|---------------------------------------------------------------------------------------------- |------------------------------------------------------------------------------------------------------- |------------------------------------------------------------------------------------------------------ |------------------------------------------------------------------------------------------------------ |
49+
| > [Download](https://github.com/jetkai/openai-for-java/releases/download/1.1.0/openai.jar) < | > [Download](https://github.com/jetkai/openai-for-java/releases/download/1.1.0/openai-excldeps.jar) < | > [Download](https://github.com/jetkai/openai-for-java/releases/download/1.1.0/openai-javadoc.jar) < | > [Download](https://github.com/jetkai/openai-for-java/releases/download/1.1.0/openai-sources.jar) < |
2150

22-
#### Other:
23-
- [openai-sources.jar](https://github.com/jetkai/openai-for-java/releases/download/1.1.0/openai-sources.jar)
24-
- [openai-javadoc.jar](https://github.com/jetkai/openai-for-java/releases/download/1.1.0/openai-javadoc.jar)
51+
## Available API(s) `March 2023`
2552

26-
## Minimum Requirements
27-
- JDK 11
28-
- An OpenAI [API Key](https://platform.openai.com/account/api-keys)
53+
✅ ChatGPT 3.5 (Latest) - `using CreateChatCompletion`
54+
55+
✅ Spell Checking - `using CreateCompletion`
56+
57+
✅ Transcriptions (From Audio File) - `using CreateTranscription`
58+
59+
✅ Translations (From Text or Audio File) - `using CreateTranslation` / `CreateTranscriptionTranslation`
60+
61+
✅ AI Image Creation / Editing - `using CreateImage` / `CreateImageEdit` / `CreateImageVariation`
62+
63+
---
64+
65+
###### [OpenAI API Reference](https://platform.openai.com/docs/api-reference/)
2966

30-
## Available API(s) `March 2023`
3167
- [ListModel](https://platform.openai.com/docs/api-reference/models/retrieve) -> `https://api.openai.com/v1/models`
3268
- [ListModels](https://platform.openai.com/docs/api-reference/models/list) -> `https://api.openai.com/v1/models/{model}`
3369
- [CreateCompletion](https://platform.openai.com/docs/api-reference/completions/create) -> `https://api.openai.com/v1/completions`
@@ -38,14 +74,38 @@
3874
- [CreateImageVariation](https://platform.openai.com/docs/api-reference/images/create-variation) -> `https://api.openai.com/v1/images/variations`
3975
- [CreateEmbeddings](https://platform.openai.com/docs/api-reference/embeddings/create) -> `https://api.openai.com/v1/embeddings`
4076
- [CreateTranscription](https://platform.openai.com/docs/api-reference/audio/create) -> `https://api.openai.com/v1/audio/transcriptions`
41-
- [CreateTranslation](https://platform.openai.com/docs/api-reference/audio/create) -> `https://api.openai.com/v1/audio/translations`
77+
- [CreateTranscriptionAndTranslation](https://platform.openai.com/docs/api-reference/audio/create) -> `https://api.openai.com/v1/audio/translations`
78+
- [CreateTranslation](https://platform.openai.com/docs/api-reference/audio/create) -> `https://api.openai.com/v1/completions`
79+
80+
---
4281

4382
# Source Code (Examples)
4483

4584
## [ChatGPT-3.5 Turbo](https://github.com/jetkai/openai-for-java/blob/main/src/main/java/examples/ExampleChatGPT.java)
85+
4686
Scenario: Say "Hello" to the AI and ask the AI to respond back with the last thing I said.
87+
4788
```java
48-
private String exampleBuilders(String message) {
89+
public static void main(String[] args) {
90+
ExampleChatGPT gpt = new ExampleChatGPT();
91+
92+
//The first message that we want to send
93+
String message1 = "Hello ChatGPT!";
94+
//The second message that we want to send
95+
String message2 = "What was the first thing I said?";
96+
97+
//Response 1 from ChatGPT
98+
String response1 = gpt.exampleBuilders(message1);
99+
System.out.println("Sent: " + message1);
100+
System.out.println("Response: " + response1);
101+
102+
//Response 2 from ChatGPT
103+
String response2 = gpt.exampleBuilders(message2);
104+
System.out.println("Sent: " + message2);
105+
System.out.println("Response: " + response2);
106+
}
107+
108+
private String exampleBuilders(String message) {
49109
//Create the Message Data object with the message we wish to send
50110
ChatCompletionMessageData messageData = ChatCompletionMessageData.builder()
51111
.setRole("user")
@@ -81,51 +141,12 @@
81141
//Parse the response back as plain-text & replace \n & ascii characters (Šťŕĭńġ -> String)
82142
return createChatCompletion.asNormalizedText();
83143
}
84-
85-
private String exampleHttpClientProxy(String message) {
86-
ProxySelector proxySelector = ProxySelector.of(new InetSocketAddress("1.0.205.87", 8080));
87-
88-
HttpClient httpClient = HttpClient.newBuilder()
89-
.version(HttpClient.Version.HTTP_2)
90-
.followRedirects(HttpClient.Redirect.ALWAYS)
91-
.proxy(proxySelector)
92-
.connectTimeout(Duration.ofSeconds(10)) //10 seconds timeout
93-
.build();
94-
95-
//Create the Message Data object with the message we wish to send
96-
ChatCompletionMessageData messageData = ChatCompletionMessageData.create(message);
97-
98-
//Store the message that we want to send, to the MessageHistory List
99-
messageHistory.add(messageData);
100-
101-
//Build the data structure which contains the message history and model information
102-
ChatCompletionData completionData = ChatCompletionData.create(messageHistory);
103-
104-
//Sends the request to OpenAI's endpoint & parses the response data
105-
//Instead of openAI.sendRequest(); you can initialize the request for the class manually
106-
//openAI.createChatCompletion().initialize();
107-
OpenAI openAI = OpenAI.builder()
108-
.setApiKey(System.getenv("OPEN_AI_API_KEY"))
109-
.setHttpClient(httpClient)
110-
.build();
111-
112-
//Create instance which will return as the API class that we specified in the enum or .class
113-
//CreateChatCompletion createChatCompletion = openAI.createInstance(CreateChatCompletion.class, completionData);
114-
CreateChatCompletion createChatCompletion = openAI.createInstance(
115-
OpenAIEndpoints.CREATE_CHAT_COMPLETION, completionData
116-
);
117-
118-
//Store chat response from AI, this allows the AI to see the full history of our chat
119-
//Including both our messages and the AI's messages
120-
messageHistory.addAll(createChatCompletion.asChatResponseDataList());
121-
122-
//Parse the response back as plain-text & replace \n & ascii characters (Šťŕĭńġ -> String)
123-
return createChatCompletion.asNormalizedText();
124-
}
125144
```
126145

127146
## [AI Image Creation](https://github.com/jetkai/openai-for-java/blob/main/src/main/java/examples/ExampleImageCreation.java)
147+
128148
Scenario: Have an AI create a red panda with glasses, and have this drawn as a cartoon.
149+
129150
```java
130151
public static void main(String[] args) throws IOException {
131152
//Initialize ExampleImageCreation class
@@ -177,7 +198,9 @@
177198
```
178199

179200
## [Spelling Correction](https://github.com/jetkai/openai-for-java/blob/main/src/main/java/examples/ExampleSpellingCorrection.java)
201+
180202
Scenario: Correct the spelling within the sentence "Wha dai of the wek is it?".
203+
181204
```java
182205
public static void main(String[] args) {
183206
//Initialize ExampleSpellingCorrection class
@@ -216,7 +239,9 @@
216239
```
217240

218241
## [Translate Language](https://github.com/jetkai/openai-for-java/blob/main/src/main/java/examples/ExampleTranslation.java)
242+
219243
Scenario: Translate "Hello, how are you today?" from English to French.
244+
220245
```java
221246
public static void main(String[] args) {
222247
//Initialize ExampleTranslation class
@@ -255,6 +280,7 @@
255280
```
256281

257282
## [Audio Transcript](https://github.com/jetkai/openai-for-java/blob/main/src/main/java/examples/ExampleTranscriptionFromAudioFile.java)
283+
258284
Scenario: Create a transcript from an audio file.
259285

260286
```java
@@ -296,8 +322,9 @@
296322
```
297323

298324
## [Audio Transcript & Translate](https://github.com/jetkai/openai-for-java/blob/main/src/main/java/examples/ExampleTranslationFromAudioFile.java)
325+
299326
Scenario: Create a transcript from an audio file, then translate the transcript from English to French.
300-
327+
301328
```java
302329
public static void main(String[] args) throws URISyntaxException {
303330
//Initialize ExampleTranslationFromAudioFile class
@@ -348,6 +375,7 @@
348375
```
349376

350377
## [List Model Information](https://github.com/jetkai/openai-for-java/blob/main/src/main/java/examples/ExampleListModel.java)
378+
351379
Scenario: Get information about a specific model.
352380

353381
```java
@@ -382,7 +410,9 @@
382410
```
383411

384412
## [List All Models](https://github.com/jetkai/openai-for-java/blob/main/src/main/java/examples/ExampleListModels.java)
413+
385414
Scenario: List all the models available from OpenAI.
415+
386416
```java
387417
public static void main(String[] args) {
388418
//Initialize ExampleListModels class
@@ -561,7 +591,7 @@
561591
assertFalse(json.isEmpty());
562592
}
563593
```
564-
594+
565595
### CreateImageVariation
566596

567597
```java
@@ -683,4 +713,4 @@
683713
assertNotNull(json);
684714
assertFalse(json.isEmpty());
685715
}
686-
```
716+
```

0 commit comments

Comments
 (0)