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

Commit ea94b90

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

File tree

5 files changed

+67
-31
lines changed

5 files changed

+67
-31
lines changed

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

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
package dev.ai4j.openai4j;
22

3-
import java.net.InetSocketAddress;
4-
import java.net.Proxy;
5-
import java.nio.file.Path;
6-
import java.nio.file.Paths;
7-
import java.time.Duration;
8-
import java.util.HashMap;
9-
import java.util.List;
3+
import static dev.ai4j.openai4j.LogLevel.DEBUG;
104

115
import dev.ai4j.openai4j.chat.ChatCompletionRequest;
126
import dev.ai4j.openai4j.chat.ChatCompletionResponse;
@@ -21,78 +15,101 @@
2115
import dev.ai4j.openai4j.moderation.ModerationResult;
2216
import dev.ai4j.openai4j.spi.OpenAiClientBuilderFactory;
2317
import dev.ai4j.openai4j.spi.ServiceHelper;
18+
import java.net.InetSocketAddress;
19+
import java.net.Proxy;
20+
import java.nio.file.Path;
21+
import java.nio.file.Paths;
22+
import java.time.Duration;
23+
import java.util.HashMap;
24+
import java.util.List;
2425
import java.util.Map;
2526

26-
import static dev.ai4j.openai4j.LogLevel.DEBUG;
27-
2827
public abstract class OpenAiClient {
2928

30-
public abstract SyncOrAsyncOrStreaming<CompletionResponse> completion(
31-
OpenAiClientContext clientContext, CompletionRequest request);
32-
33-
public abstract SyncOrAsyncOrStreaming<String> completion(OpenAiClientContext clientContext,
34-
String prompt);
35-
3629
public SyncOrAsyncOrStreaming<CompletionResponse> completion(CompletionRequest request) {
3730
return completion(new OpenAiClientContext(), request);
3831
}
3932

33+
public SyncOrAsyncOrStreaming<CompletionResponse> completion(
34+
OpenAiClientContext clientContext, CompletionRequest request) {
35+
throw new UnsupportedOperationException();
36+
}
37+
4038
public SyncOrAsyncOrStreaming<String> completion(String prompt) {
4139
return completion(new OpenAiClientContext(), prompt);
4240
}
4341

42+
public SyncOrAsyncOrStreaming<String> completion(OpenAiClientContext clientContext,
43+
String prompt) {
44+
throw new UnsupportedOperationException();
45+
}
46+
4447
public SyncOrAsyncOrStreaming<ChatCompletionResponse> chatCompletion(
4548
ChatCompletionRequest request) {
4649
return chatCompletion(new OpenAiClientContext(), request);
4750
}
4851

49-
public abstract SyncOrAsyncOrStreaming<ChatCompletionResponse> chatCompletion(
52+
public SyncOrAsyncOrStreaming<ChatCompletionResponse> chatCompletion(
5053
OpenAiClientContext clientContext,
51-
ChatCompletionRequest request);
54+
ChatCompletionRequest request) {
55+
throw new UnsupportedOperationException();
56+
}
5257

5358
public SyncOrAsyncOrStreaming<String> chatCompletion(String userMessage) {
5459
return chatCompletion(new OpenAiClientContext(), userMessage);
5560
}
5661

57-
public abstract SyncOrAsyncOrStreaming<String> chatCompletion(
62+
public SyncOrAsyncOrStreaming<String> chatCompletion(
5863
OpenAiClientContext clientContext,
59-
String userMessage);
64+
String userMessage) {
65+
throw new UnsupportedOperationException();
66+
}
6067

6168
public SyncOrAsync<EmbeddingResponse> embedding(EmbeddingRequest request) {
6269
return embedding(new OpenAiClientContext(), request);
6370
}
6471

65-
public abstract SyncOrAsync<EmbeddingResponse> embedding(OpenAiClientContext clientContext,
66-
EmbeddingRequest request);
72+
public SyncOrAsync<EmbeddingResponse> embedding(OpenAiClientContext clientContext,
73+
EmbeddingRequest request) {
74+
throw new UnsupportedOperationException();
75+
}
6776

6877
public SyncOrAsync<List<Float>> embedding(String input) {
6978
return embedding(new OpenAiClientContext(), input);
7079
}
7180

72-
public abstract SyncOrAsync<List<Float>> embedding(OpenAiClientContext clientContext,
73-
String input);
81+
public SyncOrAsync<List<Float>> embedding(OpenAiClientContext clientContext,
82+
String input) {
83+
throw new UnsupportedOperationException();
84+
}
7485

7586
public SyncOrAsync<ModerationResponse> moderation(ModerationRequest request) {
7687
return moderation(new OpenAiClientContext(), request);
7788
}
7889

79-
public abstract SyncOrAsync<ModerationResponse> moderation(OpenAiClientContext clientContext,
80-
ModerationRequest request);
90+
public SyncOrAsync<ModerationResponse> moderation(OpenAiClientContext clientContext,
91+
ModerationRequest request) {
92+
throw new UnsupportedOperationException();
93+
}
8194

8295
public SyncOrAsync<ModerationResult> moderation(String input) {
8396
return moderation(new OpenAiClientContext(), input);
8497
}
8598

86-
public abstract SyncOrAsync<ModerationResult> moderation(OpenAiClientContext clientContext,
87-
String input);
99+
public SyncOrAsync<ModerationResult> moderation(OpenAiClientContext clientContext,
100+
String input) {
101+
throw new UnsupportedOperationException();
102+
}
88103

89104
public SyncOrAsync<GenerateImagesResponse> imagesGeneration(GenerateImagesRequest request) {
90105
return imagesGeneration(new OpenAiClientContext(), request);
91106
}
92107

93-
public abstract SyncOrAsync<GenerateImagesResponse> imagesGeneration(
108+
public SyncOrAsync<GenerateImagesResponse> imagesGeneration(
94109
OpenAiClientContext clientContext,
95-
GenerateImagesRequest request);
110+
GenerateImagesRequest request) {
111+
throw new UnsupportedOperationException();
112+
}
96113

97114
public abstract void shutdown();
98115

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)