Skip to content

Commit e32b728

Browse files
committed
Fixing software quality issues
1 parent 934b7ca commit e32b728

File tree

10 files changed

+18
-19
lines changed

10 files changed

+18
-19
lines changed

src/demo/java/io/github/sashirestela/openai/demo/AudioDemo.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ public void demoCallAudioSpeech() {
3434
.build();
3535
var futureSpeech = openAI.audios().speak(speechRequest);
3636
var speechResponse = futureSpeech.join();
37-
try {
38-
var audioFile = new FileOutputStream(speechFileName);
37+
try (var audioFile = new FileOutputStream(speechFileName)) {
3938
audioFile.write(speechResponse.readAllBytes());
4039
System.out.println(audioFile.getChannel().size() + " bytes");
41-
audioFile.close();
4240
} catch (Exception e) {
4341
e.printStackTrace();
4442
}

src/demo/java/io/github/sashirestela/openai/demo/ChatDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public void demoCallChatWithAudioInputOutput() {
221221

222222
private static void processResponseChunk(Chat responseChunk) {
223223
var choices = responseChunk.getChoices();
224-
if (choices.size() > 0) {
224+
if (!choices.isEmpty()) {
225225
var delta = choices.get(0).getMessage();
226226
if (delta.getContent() != null) {
227227
System.out.print(delta.getContent());

src/demo/java/io/github/sashirestela/openai/demo/CompletionDemo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ public void demoCallCompletionStreaming() {
2323
var futureCompletion = openAI.completions().createStream(completionRequest);
2424
var completionResponse = futureCompletion.join();
2525
completionResponse.forEach(CompletionDemo::processResponseChunk);
26-
;
2726
System.out.println();
2827
}
2928

3029
private static void processResponseChunk(Completion responseChunk) {
3130
var choices = responseChunk.getChoices();
32-
if (choices.size() > 0) {
31+
if (!choices.isEmpty()) {
3332
var delta = choices.get(0).getText();
3433
System.out.print(delta);
3534
}

src/demo/java/io/github/sashirestela/openai/demo/ConversationDemo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void runConversation() {
5252
List<ChatMessage> messages = new ArrayList<>();
5353
var myMessage = System.console().readLine("\nWelcome! Write any message: ");
5454
messages.add(UserMessage.of(myMessage));
55-
while (!myMessage.toLowerCase().equals("exit")) {
55+
while (!myMessage.equalsIgnoreCase("exit")) {
5656
var chatStream = openAI.chatCompletions()
5757
.createStream(ChatRequest.builder()
5858
.model("gpt-4o-mini")
@@ -93,7 +93,7 @@ private Choice getResponse(Stream<Chat> chatStream) {
9393

9494
chatStream.forEach(responseChunk -> {
9595
var choices = responseChunk.getChoices();
96-
if (choices.size() > 0) {
96+
if (!choices.isEmpty()) {
9797
var innerChoice = choices.get(0);
9898
var delta = innerChoice.getMessage();
9999
if (delta.getRole() != null) {
@@ -106,7 +106,7 @@ private Choice getResponse(Stream<Chat> chatStream) {
106106
if (delta.getToolCalls() != null) {
107107
var toolCall = delta.getToolCalls().get(0);
108108
if (toolCall.getIndex() != indexTool) {
109-
if (toolCalls.size() > 0) {
109+
if (!toolCalls.isEmpty()) {
110110
toolCalls.get(toolCalls.size() - 1).getFunction().setArguments(functionArgs.toString());
111111
functionArgs = new StringBuilder();
112112
}
@@ -120,7 +120,7 @@ private Choice getResponse(Stream<Chat> chatStream) {
120120
if (content.length() > 0) {
121121
chatMsgResponse.setContent(content.toString());
122122
}
123-
if (toolCalls.size() > 0) {
123+
if (!toolCalls.isEmpty()) {
124124
toolCalls.get(toolCalls.size() - 1).getFunction().setArguments(functionArgs.toString());
125125
chatMsgResponse.setToolCalls(toolCalls);
126126
}

src/demo/java/io/github/sashirestela/openai/demo/ConversationV2Demo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void prepareConversation() {
100100

101101
public void runConversation() {
102102
var myMessage = System.console().readLine("\nWelcome! Write any message: ");
103-
while (!myMessage.toLowerCase().equals("exit")) {
103+
while (!myMessage.equalsIgnoreCase("exit")) {
104104
openAI.threadMessages()
105105
.create(threadId, ThreadMessageRequest.builder()
106106
.role(ThreadMessageRole.USER)

src/demo/java/io/github/sashirestela/openai/demo/ImageDemo.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
public class ImageDemo extends AbstractDemo {
1212

13+
private static final String MODEL = "dall-e-2";
14+
1315
public void demoCallImageGeneration() {
1416
var imageRequest = ImageRequest.builder()
1517
.prompt("A cartoon of a hummingbird that is flying around a flower.")
1618
.n(2)
1719
.size(Size.X256)
1820
.responseFormat(ImageResponseFormat.URL)
19-
.model("dall-e-2")
21+
.model(MODEL)
2022
.build();
2123
var futureImage = openAI.images().create(imageRequest);
2224
var imageResponse = futureImage.join();
@@ -30,7 +32,7 @@ public void demoCallImageEdits() {
3032
.n(1)
3133
.size(Size.X256)
3234
.responseFormat(ImageResponseFormat.URL)
33-
.model("dall-e-2")
35+
.model(MODEL)
3436
.build();
3537
var futureImage = openAI.images().createEdits(imageEditsRequest);
3638
var imageResponse = futureImage.join();
@@ -43,7 +45,7 @@ public void demoCallImageVariations() {
4345
.n(1)
4446
.size(Size.X256)
4547
.responseFormat(ImageResponseFormat.URL)
46-
.model("dall-e-2")
48+
.model(MODEL)
4749
.build();
4850
var futureImage = openAI.images().createVariations(imageVariationsRequest);
4951
var imageResponse = futureImage.join();

src/demo/java/io/github/sashirestela/openai/demo/RealtimeDemo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class RealtimeDemo {
2323

2424
private static final int BUFFER_SIZE = 8192;
2525

26-
public static void main(String[] args) throws LineUnavailableException, InterruptedException {
26+
public static void main(String[] args) throws LineUnavailableException {
2727
var sound = new Sound();
2828

2929
var openAI = SimpleOpenAI.builder()

src/demo/java/io/github/sashirestela/openai/demo/ThreadRunStepV2Demo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515

1616
public class ThreadRunStepV2Demo extends AbstractDemo {
1717

18-
private FunctionExecutor functionExecutor;
1918
private String assistantId;
2019
private String threadId;
2120
private String threadRunId;
2221
private String threadRunStepId;
2322

2423
private void prepareDemo() {
24+
FunctionExecutor functionExecutor;
2525
List<FunctionDef> functionList = new ArrayList<>();
2626
functionList.add(FunctionDef.builder()
2727
.name("CurrentTemperature")

src/main/java/io/github/sashirestela/openai/OpenAIBeta2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ default VectorStore createAndPoll(VectorStoreRequest request) {
638638
.timeValue(1)
639639
.queryMethod(vs -> getOne(vs.getId()).join())
640640
.whileMethod(vs -> !vs.getStatus().equals(VectorStoreStatus.COMPLETED)
641-
|| vs.getFileCounts().getCompleted() != vs.getFileCounts().getTotal())
641+
|| !vs.getFileCounts().getCompleted().equals(vs.getFileCounts().getTotal()))
642642
.build()
643643
.execute(vectorStore);
644644
}

src/main/java/io/github/sashirestela/openai/common/function/FunctionExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public FunctionExecutor(List<FunctionDef> functions) {
3030
public List<Tool> getToolFunctions() {
3131
return mapFunctions.values()
3232
.stream()
33-
.map(func -> Tool.function(func))
33+
.map(Tool::function)
3434
.collect(Collectors.toList());
3535
}
3636

@@ -63,7 +63,7 @@ public void enrollFunctions(List<FunctionDef> functions) {
6363
throw new SimpleUncheckedException("No functions were entered.", "", null);
6464
}
6565
mapFunctions.clear();
66-
functions.forEach(function -> enrollFunction(function));
66+
functions.forEach(this::enrollFunction);
6767
}
6868

6969
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)