Skip to content

Commit 4e257e4

Browse files
committed
additional testing added, removing OpenAI.create();
1 parent 7537e5e commit 4e257e4

15 files changed

+132
-16
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "io.github.jetkai"
7-
version = "1.1.0"
7+
version = "1.1.1"
88

99
java {
1010
//withSourcesJar()

src/main/java/io/github/jetkai/openai/openai/OpenAI.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* OpenAI
2121
*
2222
* @author <a href="https://github.com/jetkai">Kai</a>
23-
* @version 1.1.0
23+
* @version 1.1.1
2424
* {@code - 07/03/2023}
2525
* @since 1.0.0
2626
* {@code - 02/03/2023}
@@ -29,10 +29,6 @@ public abstract class OpenAI {
2929

3030
public OpenAI() { }
3131

32-
public static OpenAI create() {
33-
return builder().build();
34-
}
35-
3632
public static Builder builder() {
3733
return new OpenAIBuilderImpl();
3834
}

src/test/java/CreateChatCompletionTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* CreateChatCompletionTest
1717
*
1818
* @author <a href="https://github.com/jetkai">Kai</a>
19-
* @version 1.0.0
19+
* @version 1.1.1
2020
* @created 02/03/2023
2121
* @last-update 03/03/2023
2222
*/
@@ -69,6 +69,9 @@ void createChatCompletionTest() {
6969
Optional<CreateChatCompletion> optionalChatCompletion = openAI.chatCompletion();
7070
assertFalse(optionalChatCompletion.isEmpty());
7171

72+
//Additionally check the getter method is not null
73+
assertNotNull(openAI.getChatCompletion());
74+
7275
CreateChatCompletion createChatCompletion = optionalChatCompletion.get();
7376

7477
//Data structure example

src/test/java/CreateCompletionTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* CreateCompletionTest
1414
*
1515
* @author <a href="https://github.com/jetkai">Kai</a>
16-
* @version 1.0.0
16+
* @version 1.1.1
1717
* @created 02/03/2023
1818
* @last-update 03/03/2023
1919
*/
@@ -92,6 +92,9 @@ void createCompletionTest() {
9292
Optional<CreateCompletion> optionalCreateCompletion = openAI.completion();
9393
assertFalse(optionalCreateCompletion.isEmpty());
9494

95+
//Additionally check the getter method is not null
96+
assertNotNull(openAI.getCompletion());
97+
9598
CreateCompletion createCompletion = optionalCreateCompletion.get();
9699

97100
assertNotNull(createCompletion.asStringArray());

src/test/java/CreateEditTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* CreateEditTest
1414
*
1515
* @author <a href="https://github.com/jetkai">Kai</a>
16-
* @version 1.0.0
16+
* @version 1.1.1
1717
* @created 02/03/2023
1818
* @last-update 03/03/2023
1919
*/
@@ -55,6 +55,9 @@ void createEditTest() {
5555
Optional<CreateEdit> optionalCreateEdit = openAI.edit(); //You can call "data" to see the response
5656
assertFalse(optionalCreateEdit.isEmpty());
5757

58+
//Additionally check the getter method is not null
59+
assertNotNull(openAI.getEdit());
60+
5861
CreateEdit createEdit = optionalCreateEdit.get();
5962

6063
//Data structure example

src/test/java/CreateEmbeddingTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* CreateEmbeddingTest
1515
*
1616
* @author <a href="https://github.com/jetkai">Kai</a>
17-
* @version 1.0.0
17+
* @version 1.1.1
1818
* @created 02/03/2023
1919
* @last-update 03/03/2023
2020
*/
@@ -50,6 +50,9 @@ void createEmbeddingTest() {
5050
Optional<CreateEmbedding> optionalEmbedding = openAI.embedding();
5151
assertFalse(optionalEmbedding.isEmpty());
5252

53+
//Additionally check the getter method is not null
54+
assertNotNull(openAI.getEmbedding());
55+
5356
CreateEmbedding createEmbedding = optionalEmbedding.get();
5457

5558
//Data structure example

src/test/java/CreateImageEditTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* CreateImageEditTest
1717
*
1818
* @author <a href="https://github.com/jetkai">Kai</a>
19-
* @version 1.0.0
19+
* @version 1.1.1
2020
* @created 02/03/2023
2121
* @last-update 03/03/2023
2222
*/
@@ -85,6 +85,9 @@ void createImageEditTest() {
8585
Optional<CreateImageEdit> optionalCreateImageEdit = openAI.imageEdit();
8686
assertFalse(optionalCreateImageEdit.isEmpty());
8787

88+
//Additionally check the getter method is not null
89+
assertNotNull(openAI.getImageEdit());
90+
8891
CreateImageEdit createImageEdit = optionalCreateImageEdit.get();
8992

9093
//Data structure example

src/test/java/CreateImageTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
import static org.junit.jupiter.api.Assertions.assertFalse;
1010
import static org.junit.jupiter.api.Assertions.assertNotNull;
1111

12+
/**
13+
* CreateImageTests
14+
*
15+
* @author <a href="https://github.com/jetkai">Kai</a>
16+
* @version 1.1.1
17+
* @created 02/03/2023
18+
* @last-update 03/03/2023
19+
*/
1220
public class CreateImageTests {
1321

1422
@Test
@@ -45,6 +53,9 @@ void createImageTest() {
4553
Optional<CreateImage> optionalCreateImage = openAI.image();
4654
assertFalse(optionalCreateImage.isEmpty());
4755

56+
//Additionally check the getter method is not null
57+
assertNotNull(openAI.getImage());
58+
4859
CreateImage createImage = optionalCreateImage.get();
4960

5061
//Grabs the first image in the array, if your "setN" is higher than 1, then use imageArray

src/test/java/CreateImageVariationTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* CreateImageVariationTest
1818
*
1919
* @author <a href="https://github.com/jetkai">Kai</a>
20-
* @version 1.0.0
20+
* @version 1.1.1
2121
* @created 02/03/2023
2222
* @last-update 03/03/2023
2323
*/
@@ -69,6 +69,9 @@ void createImageVariationTest() {
6969
Optional<CreateImageVariation> optionalCreateImageVariation = openAI.imageVariation();
7070
assertFalse(optionalCreateImageVariation.isEmpty());
7171

72+
//Additionally check the getter method is not null
73+
assertNotNull(openAI.getImageVariation());
74+
7275
CreateImageVariation createImageVariation = optionalCreateImageVariation.get();
7376

7477
//String List example (contains all the image urls)

src/test/java/CreateInstanceTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import io.github.jetkai.openai.api.ListModel;
2+
import io.github.jetkai.openai.net.OpenAIEndpoints;
3+
import io.github.jetkai.openai.openai.OpenAI;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.junit.jupiter.api.Assertions.assertNotNull;
7+
8+
/**
9+
* CreateInstanceTest
10+
*
11+
* @author <a href="https://github.com/jetkai">Kai</a>
12+
* @version 1.1.1
13+
* @created 02/03/2023
14+
* @last-update 05/03/2023
15+
*/
16+
public class CreateInstanceTest {
17+
18+
@Test
19+
void createInstanceTest() {
20+
String apiKey = System.getenv("OPEN_AI_API_KEY");
21+
String organization = System.getenv("OPEN_AI_ORGANIZATION");
22+
assertNotNull(apiKey);
23+
assertNotNull(organization);
24+
25+
OpenAI openAI = OpenAI.builder()
26+
.setApiKey(apiKey)
27+
.setOrganization(organization)
28+
.build();
29+
30+
ListModel instance1 = openAI.createInstance(ListModel.class, "davinci");
31+
assertNotNull(instance1);
32+
33+
ListModel instance2 = openAI.createInstance(OpenAIEndpoints.LIST_MODEL, "davinci");
34+
assertNotNull(instance2);
35+
}
36+
37+
}

src/test/java/CreateTranscriptionTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* CreateTranscriptionTest
1717
*
1818
* @author <a href="https://github.com/jetkai">Kai</a>
19-
* @version 1.0.1
19+
* @version 1.1.1
2020
* @created 02/03/2023
2121
* @last-update 05/03/2023
2222
*/
@@ -60,6 +60,9 @@ void createTranscriptionTest() {
6060
Optional<CreateTranscription> optionalCreateTranscription = openAI.transcription();
6161
assertFalse(optionalCreateTranscription.isEmpty());
6262

63+
//Additionally check the getter method is not null
64+
assertNotNull(openAI.getTranscription());
65+
6366
CreateTranscription createTranscription = optionalCreateTranscription.get();
6467

6568
//Transcript as a string (Audio File -> English)

src/test/java/CreateTranslationTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* CreateTranslationTests
2222
*
2323
* @author <a href="https://github.com/jetkai">Kai</a>
24-
* @version 1.0.0
24+
* @version 1.1.1
2525
* @created 02/03/2023
2626
* @last-update 03/03/2023
2727
*/
@@ -67,6 +67,9 @@ void createTranslationTest() {
6767
Optional<CreateTranslation> optionalCreateTranslation = openAI.translation();
6868
assertFalse(optionalCreateTranslation.isEmpty());
6969

70+
//Additionally check the getter method is not null
71+
assertNotNull(openAI.getTranslation());
72+
7073
CreateTranslation createTranslation = optionalCreateTranslation.get();
7174

7275
//Data structure example
@@ -136,6 +139,9 @@ void createAudioTranslationTest() {
136139
Optional<CreateTranscriptionTranslation> optionalTranscriptionTranslation = openAI.transcriptionTranslation();
137140
assertFalse(optionalTranscriptionTranslation.isEmpty());
138141

142+
//Additionally check the getter method is not null
143+
assertNotNull(openAI.getTranscriptionTranslation());
144+
139145
CreateTranscriptionTranslation transcriptionTranslation = optionalTranscriptionTranslation.get();
140146

141147
//Data structure example

src/test/java/GetOpenAITests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import io.github.jetkai.openai.api.ListModel;
2+
import io.github.jetkai.openai.openai.OpenAI;
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
7+
/**
8+
* GetOpenAITests
9+
*
10+
* @author <a href="https://github.com/jetkai">Kai</a>
11+
* @version 1.1.1
12+
* @created 02/03/2023
13+
* @last-update 05/03/2023
14+
*/
15+
public class GetOpenAITests {
16+
17+
@Test
18+
void getOpenAITests() {
19+
String apiKey = System.getenv("OPEN_AI_API_KEY");
20+
String organization = System.getenv("OPEN_AI_ORGANIZATION");
21+
assertNotNull(apiKey);
22+
assertNotNull(organization);
23+
24+
OpenAI openAI = OpenAI.builder()
25+
.setApiKey(apiKey)
26+
.setOrganization(organization)
27+
.build();
28+
29+
ListModel instance1 = openAI.createInstance(ListModel.class, "davinci");
30+
assertNotNull(instance1);
31+
32+
assertNotNull(openAI.getHttpClient());
33+
assertNotNull(openAI.getHttpClientInstance());
34+
assertNotNull(openAI.getApiKey());
35+
assertNotNull(openAI.getOrganization());
36+
37+
}
38+
39+
}

src/test/java/ListModelTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* ListModelTest
1212
*
1313
* @author <a href="https://github.com/jetkai">Kai</a>
14-
* @version 1.0.0
14+
* @version 1.1.1
1515
* @created 02/03/2023
1616
* @last-update 03/03/2023
1717
*/
@@ -45,6 +45,9 @@ void getModelTest() {
4545
Optional<ListModel> optionalGetModel = openAI.model();
4646
assertFalse(optionalGetModel.isEmpty());
4747

48+
//Additionally check the getter method is not null
49+
assertNotNull(openAI.getModel());
50+
4851
ListModel listModel = optionalGetModel.get();
4952

5053
//Data structure example

src/test/java/ListModelsTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* ListModelsTest
1313
*
1414
* @author <a href="https://github.com/jetkai">Kai</a>
15-
* @version 1.0.0
15+
* @version 1.1.1
1616
* @created 02/03/2023
1717
* @last-update 03/03/2023
1818
*/
@@ -40,6 +40,9 @@ void getModelsTest() {
4040
Optional<ListModels> optionalGetModels = openAI.models();
4141
assertFalse(optionalGetModels.isEmpty());
4242

43+
//Additionally check the getter method is not null
44+
assertNotNull(openAI.getModels());
45+
4346
ListModels listModels = optionalGetModels.get();
4447

4548
//Data structure example

0 commit comments

Comments
 (0)