Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Commit f256821

Browse files
Changed abstract methods in OpenAiClient to default unimplemented ones
1 parent 82d4e6c commit f256821

File tree

5 files changed

+60
-22
lines changed

5 files changed

+60
-22
lines changed

src/main/java/dev/ai4j/openai4j/OpenAiClient.java

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,77 +22,96 @@
2222
import dev.ai4j.openai4j.spi.OpenAiClientBuilderFactory;
2323
import dev.ai4j.openai4j.spi.ServiceHelper;
2424
import java.util.Map;
25+
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
2526

2627
import static dev.ai4j.openai4j.LogLevel.DEBUG;
2728

2829
public abstract class OpenAiClient {
2930

30-
public abstract SyncOrAsyncOrStreaming<CompletionResponse> completion(
31-
OpenAiClientContext clientContext, CompletionRequest request);
32-
33-
public abstract SyncOrAsyncOrStreaming<String> completion(OpenAiClientContext clientContext,
34-
String prompt);
35-
3631
public SyncOrAsyncOrStreaming<CompletionResponse> completion(CompletionRequest request) {
3732
return completion(new OpenAiClientContext(), request);
3833
}
3934

35+
public SyncOrAsyncOrStreaming<CompletionResponse> completion(
36+
OpenAiClientContext clientContext, CompletionRequest request) {
37+
throw new NotImplementedException();
38+
}
39+
4040
public SyncOrAsyncOrStreaming<String> completion(String prompt) {
4141
return completion(new OpenAiClientContext(), prompt);
4242
}
4343

44+
public SyncOrAsyncOrStreaming<String> completion(OpenAiClientContext clientContext,
45+
String prompt) {
46+
throw new NotImplementedException();
47+
}
48+
4449
public SyncOrAsyncOrStreaming<ChatCompletionResponse> chatCompletion(
4550
ChatCompletionRequest request) {
4651
return chatCompletion(new OpenAiClientContext(), request);
4752
}
4853

49-
public abstract SyncOrAsyncOrStreaming<ChatCompletionResponse> chatCompletion(
54+
public SyncOrAsyncOrStreaming<ChatCompletionResponse> chatCompletion(
5055
OpenAiClientContext clientContext,
51-
ChatCompletionRequest request);
56+
ChatCompletionRequest request) {
57+
throw new NotImplementedException();
58+
}
5259

5360
public SyncOrAsyncOrStreaming<String> chatCompletion(String userMessage) {
5461
return chatCompletion(new OpenAiClientContext(), userMessage);
5562
}
5663

57-
public abstract SyncOrAsyncOrStreaming<String> chatCompletion(
64+
public SyncOrAsyncOrStreaming<String> chatCompletion(
5865
OpenAiClientContext clientContext,
59-
String userMessage);
66+
String userMessage) {
67+
throw new NotImplementedException();
68+
}
6069

6170
public SyncOrAsync<EmbeddingResponse> embedding(EmbeddingRequest request) {
6271
return embedding(new OpenAiClientContext(), request);
6372
}
6473

65-
public abstract SyncOrAsync<EmbeddingResponse> embedding(OpenAiClientContext clientContext,
66-
EmbeddingRequest request);
74+
public SyncOrAsync<EmbeddingResponse> embedding(OpenAiClientContext clientContext,
75+
EmbeddingRequest request) {
76+
throw new NotImplementedException();
77+
}
6778

6879
public SyncOrAsync<List<Float>> embedding(String input) {
6980
return embedding(new OpenAiClientContext(), input);
7081
}
7182

72-
public abstract SyncOrAsync<List<Float>> embedding(OpenAiClientContext clientContext,
73-
String input);
83+
public SyncOrAsync<List<Float>> embedding(OpenAiClientContext clientContext,
84+
String input) {
85+
throw new NotImplementedException();
86+
}
7487

7588
public SyncOrAsync<ModerationResponse> moderation(ModerationRequest request) {
7689
return moderation(new OpenAiClientContext(), request);
7790
}
7891

79-
public abstract SyncOrAsync<ModerationResponse> moderation(OpenAiClientContext clientContext,
80-
ModerationRequest request);
92+
public SyncOrAsync<ModerationResponse> moderation(OpenAiClientContext clientContext,
93+
ModerationRequest request) {
94+
throw new NotImplementedException();
95+
}
8196

8297
public SyncOrAsync<ModerationResult> moderation(String input) {
8398
return moderation(new OpenAiClientContext(), input);
8499
}
85100

86-
public abstract SyncOrAsync<ModerationResult> moderation(OpenAiClientContext clientContext,
87-
String input);
101+
public SyncOrAsync<ModerationResult> moderation(OpenAiClientContext clientContext,
102+
String input) {
103+
throw new NotImplementedException();
104+
}
88105

89106
public SyncOrAsync<GenerateImagesResponse> imagesGeneration(GenerateImagesRequest request) {
90107
return imagesGeneration(new OpenAiClientContext(), request);
91108
}
92109

93-
public abstract SyncOrAsync<GenerateImagesResponse> imagesGeneration(
110+
public SyncOrAsync<GenerateImagesResponse> imagesGeneration(
94111
OpenAiClientContext clientContext,
95-
GenerateImagesRequest request);
112+
GenerateImagesRequest request) {
113+
throw new NotImplementedException();
114+
}
96115

97116
public abstract void shutdown();
98117

src/main/java/dev/ai4j/openai4j/chat/ChatCompletionModel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public enum ChatCompletionModel {
2020
GPT_4_32K_0314("gpt-4-32k-0314"),
2121
GPT_4_32K_0613("gpt-4-32k-0613"),
2222

23+
@Deprecated
24+
GPT_4_VISION_PREVIEW("gpt-4-vision-preview"),
2325
GPT_4O("gpt-4o"),
2426
GPT_4O_2024_05_13("gpt-4o-2024-05-13");
2527

src/test/java/dev/ai4j/openai4j/chat/ChatCompletionAsyncTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void testSimpleApi() throws Exception {
5252
@EnumSource(value = ChatCompletionModel.class, mode = EXCLUDE, names = {
5353
"GPT_3_5_TURBO_0125", // don't have access to it yet
5454
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
55+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
5556
})
5657
void testCustomizableApi(ChatCompletionModel model) throws Exception {
5758

@@ -96,6 +97,7 @@ void testCustomizableApi(ChatCompletionModel model) throws Exception {
9697
"GPT_3_5_TURBO_0125", // don't have access to it yet
9798
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
9899
"GPT_4_0314", // Does not support tools/functions
100+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including tools
99101
})
100102
void testTools(ChatCompletionModel model) throws Exception {
101103

@@ -160,6 +162,7 @@ void testTools(ChatCompletionModel model) throws Exception {
160162
"GPT_3_5_TURBO_0125", // don't have access to it yet
161163
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
162164
"GPT_4_0314", // Does not support tools/functions
165+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including functions
163166
})
164167
void testFunctions(ChatCompletionModel model) throws Exception {
165168

@@ -218,6 +221,7 @@ void testFunctions(ChatCompletionModel model) throws Exception {
218221
"GPT_3_5_TURBO_0125", // don't have access to it yet
219222
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
220223
"GPT_4_0314", // Does not support tools/functions
224+
"GPT_4_VISION_PREVIEW" // does not support many things now, including tools
221225
})
222226
void testToolChoice(ChatCompletionModel model) throws Exception {
223227

@@ -282,6 +286,7 @@ void testToolChoice(ChatCompletionModel model) throws Exception {
282286
"GPT_3_5_TURBO_0125", // don't have access to it yet
283287
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
284288
"GPT_4_0314", // Does not support tools/functions
289+
"GPT_4_VISION_PREVIEW"
285290
})
286291
void testFunctionChoice(ChatCompletionModel model) throws Exception {
287292

src/test/java/dev/ai4j/openai4j/chat/ChatCompletionStreamingTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void testSimpleApi() throws Exception {
5858
@EnumSource(value = ChatCompletionModel.class, mode = EXCLUDE, names = {
5959
"GPT_3_5_TURBO_0125", // don't have access to it yet
6060
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
61+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
6162
})
6263
void testCustomizableApi(ChatCompletionModel model) throws Exception {
6364

@@ -106,6 +107,7 @@ void testCustomizableApi(ChatCompletionModel model) throws Exception {
106107
"GPT_3_5_TURBO_0125", // don't have access to it yet
107108
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
108109
"GPT_4_0314", // Does not support tools/functions
110+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
109111
})
110112
void testTools(ChatCompletionModel model) throws Exception {
111113

@@ -223,6 +225,7 @@ void testTools(ChatCompletionModel model) throws Exception {
223225
"GPT_3_5_TURBO_0125", // don't have access to it yet
224226
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
225227
"GPT_4_0314", // Does not support tools/functions
228+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
226229
})
227230
void testFunctions(ChatCompletionModel model) throws Exception {
228231

@@ -320,6 +323,7 @@ void testFunctions(ChatCompletionModel model) throws Exception {
320323
"GPT_4_TURBO_PREVIEW", // keeps returning "felsius" as temp unit
321324
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
322325
"GPT_4_0314", // Does not support tools/functions
326+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
323327
})
324328
void testToolChoice(ChatCompletionModel model) throws Exception {
325329

@@ -437,6 +441,7 @@ void testToolChoice(ChatCompletionModel model) throws Exception {
437441
"GPT_3_5_TURBO_0125", // don't have access to it yet
438442
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
439443
"GPT_4_0314", // Does not support tools/functions
444+
"GPT_4_VISION_PREVIEW"
440445
})
441446
void testFunctionChoice(ChatCompletionModel model) throws Exception {
442447

src/test/java/dev/ai4j/openai4j/chat/ChatCompletionTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void testSimpleApi() {
5454
@EnumSource(value = ChatCompletionModel.class, mode = EXCLUDE, names = {
5555
"GPT_3_5_TURBO_0125", // don't have access to it yet
5656
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
57+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
5758
})
5859
void testCustomizableApi(ChatCompletionModel model) {
5960

@@ -91,6 +92,7 @@ void testCustomizableApi(ChatCompletionModel model) {
9192
"GPT_3_5_TURBO_0125", // don't have access to it yet
9293
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
9394
"GPT_4_0314", // Does not support tools/functions
95+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
9496
})
9597
void testTools(ChatCompletionModel model) {
9698

@@ -148,6 +150,7 @@ void testTools(ChatCompletionModel model) {
148150
"GPT_3_5_TURBO_0125", // don't have access to it yet
149151
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
150152
"GPT_4_0314", // Does not support tools/functions
153+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
151154
})
152155
void testFunctions(ChatCompletionModel model) {
153156

@@ -199,6 +202,7 @@ void testFunctions(ChatCompletionModel model) {
199202
"GPT_3_5_TURBO_0125", // don't have access to it yet
200203
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
201204
"GPT_4_0314", // Does not support tools/functions
205+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
202206
})
203207
void testToolChoice(ChatCompletionModel model) {
204208

@@ -256,6 +260,7 @@ void testToolChoice(ChatCompletionModel model) {
256260
"GPT_3_5_TURBO_0125", // don't have access to it yet
257261
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
258262
"GPT_4_0314", // Does not support tools/functions
263+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
259264
})
260265
void testFunctionChoice(ChatCompletionModel model) {
261266

@@ -311,7 +316,8 @@ void testFunctionChoice(ChatCompletionModel model) {
311316

312317
"GPT_4_TURBO_PREVIEW",
313318
"GPT_4_1106_PREVIEW",
314-
"GPT_4_0125_PREVIEW"
319+
"GPT_4_0125_PREVIEW",
320+
"GPT_4O"
315321
})
316322
void testParallelTools(ChatCompletionModel model) {
317323

@@ -449,7 +455,8 @@ void testGpt4Vision() {
449455
@ParameterizedTest
450456
@EnumSource(value = ChatCompletionModel.class, mode = EXCLUDE, names = {
451457
"GPT_3_5_TURBO_0125", // don't have access to it yet
452-
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613" // I don't have access to these models
458+
"GPT_4_32K", "GPT_4_32K_0314", "GPT_4_32K_0613", // I don't have access to these models
459+
"GPT_4_VISION_PREVIEW" // Does not support many things now, including logit_bias and response_format
453460
})
454461
void testUserMessageWithStringContent(ChatCompletionModel model) {
455462

0 commit comments

Comments
 (0)