Skip to content

Commit

Permalink
Fix some Sonar code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Jan 19, 2024
1 parent a155c7e commit 29c42ad
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ public record File(
long createdAt,
String filename,
String purpose,
@Deprecated String status) {}
@Deprecated(forRemoval = true) String status) {}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private Optional<OpenAIException.Error> getErrorFromHttpResponse(HttpResponse<?>
} else if (httpResponse.body() instanceof Path path) {
body = Files.readAllBytes(path);
} else if (httpResponse.body() instanceof Stream<?> stream) {
body = stream.map(elem -> (String) elem).collect(Collectors.joining()).getBytes();
body = stream.map(String.class::cast).collect(Collectors.joining()).getBytes();
} else {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class OpenAIAssistantsApiIntegrationTest extends OpenAIIntegrationTestBase {
class OpenAIAssistantsApiIntegrationTest extends OpenAIIntegrationTestBase {

private static final Map<String, String> METADATA = Map.of("modified", "true", "user", "abc123");

@Test
public void testThreadsClient() {
void testThreadsClient() {
ThreadsClient threadsClient = openAI.threadsClient();

CreateThreadRequest.Message message =
Expand Down Expand Up @@ -42,7 +42,7 @@ public void testThreadsClient() {
}

@Test
public void testMessagesClient() {
void testMessagesClient() {
ThreadsClient threadsClient = openAI.threadsClient();

MessagesClient messagesClient = openAI.messagesClient();
Expand Down Expand Up @@ -113,7 +113,7 @@ public void testMessagesClient() {
}

@Test
public void testAssistantsClient() {
void testAssistantsClient() {
AssistantsClient assistantsClient = openAI.assistantsClient();

File file = uploadRealEstateAgentAssistantFile();
Expand Down Expand Up @@ -179,7 +179,7 @@ public void testAssistantsClient() {
}

@Test
public void testRunsClient() {
void testRunsClient() {
ThreadsClient threadsClient = openAI.threadsClient();
AssistantsClient assistantsClient = openAI.assistantsClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class OpenAIIntegrationTest extends OpenAIIntegrationTestBase {
class OpenAIIntegrationTest extends OpenAIIntegrationTestBase {

@Test
public void testUnauthorizedRequest() {
void testUnauthorizedRequest() {
OpenAI unauthorizedOpenAI = OpenAI.newBuilder("foobar").build();

OpenAIException exception =
Expand All @@ -30,7 +30,7 @@ public void testUnauthorizedRequest() {
}

@Test
public void testChatClient() {
void testChatClient() {
ChatClient chatClient = openAI.chatClient();

CreateChatCompletionRequest request =
Expand Down Expand Up @@ -97,7 +97,7 @@ public void onComplete() {
}

@Test
public void testModelsClient() {
void testModelsClient() {
ModelsClient modelsClient = openAI.modelsClient();

List<Model> models = modelsClient.listModels();
Expand All @@ -110,7 +110,7 @@ public void testModelsClient() {
}

@Test
public void testAudioClient(@TempDir Path tempDir) {
void testAudioClient(@TempDir Path tempDir) {
AudioClient audioClient = openAI.audioClient();

SpeechRequest speechRequest =
Expand Down Expand Up @@ -147,7 +147,7 @@ public void testAudioClient(@TempDir Path tempDir) {

@Test
@Disabled("Image models are costly")
public void testImagesClient() {
void testImagesClient() {
ImagesClient imagesClient = openAI.imagesClient();

CreateImageRequest createImageRequest =
Expand Down Expand Up @@ -193,7 +193,7 @@ public void testImagesClient() {
}

@Test
public void testModerationsClient() {
void testModerationsClient() {
ModerationsClient moderationsClient = openAI.moderationsClient();

ModerationRequest request =
Expand All @@ -207,7 +207,7 @@ public void testModerationsClient() {
}

@Test
public void testEmbeddingsClient() {
void testEmbeddingsClient() {
EmbeddingsClient embeddingsClient = openAI.embeddingsClient();

EmbeddingsRequest request =
Expand All @@ -224,7 +224,7 @@ public void testEmbeddingsClient() {
}

@Test
public void testFilesClient() {
void testFilesClient() {
FilesClient filesClient = openAI.filesClient();

Path jsonlFile = getTestResource("/mydata.jsonl");
Expand All @@ -245,7 +245,7 @@ public void testFilesClient() {

@Test
@Disabled("Fine-tuning models are costly")
public void testFineTuningClient() {
void testFineTuningClient() {
FilesClient filesClient = openAI.filesClient();
FineTuningClient fineTuningClient = openAI.fineTuningClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.RepeatedTest;

public class OpenApiSpecificationValidationTest {
class OpenApiSpecificationValidationTest {

private static final String OPEN_AI_SPECIFICATION_URL =
"https://github.com/openai/openai-openapi/raw/master/openapi.yaml";
Expand All @@ -35,7 +35,7 @@ public static void setUp() {
}

@RepeatedTest(50)
public void validateAudio() {
void validateAudio() {
SpeechRequest speechRequest = testDataUtil.randomSpeechRequest();

Request request =
Expand All @@ -47,7 +47,7 @@ public void validateAudio() {
}

@RepeatedTest(50)
public void validateChat() {
void validateChat() {
CreateChatCompletionRequest createChatCompletionRequest =
testDataUtil.randomCreateChatCompletionRequest();

Expand All @@ -65,7 +65,7 @@ public void validateChat() {
}

@RepeatedTest(50)
public void validateEmbeddings() {
void validateEmbeddings() {
EmbeddingsRequest embeddingsRequest = testDataUtil.randomEmbeddingsRequest();

Embeddings embeddings = testDataUtil.randomEmbeddings();
Expand All @@ -80,7 +80,7 @@ public void validateEmbeddings() {
}

@RepeatedTest(50)
public void validateFineTuning() {
void validateFineTuning() {
CreateFineTuningJobRequest createFineTuningJobRequest =
testDataUtil.randomCreateFineTuningJobRequest();

Expand Down Expand Up @@ -117,7 +117,7 @@ public void validateFineTuning() {
}

@RepeatedTest(50)
public void validateFiles() {
void validateFiles() {
File file = testDataUtil.randomFile();

Response response = createResponseWithBody(serializeObject(file));
Expand All @@ -126,7 +126,7 @@ public void validateFiles() {
}

@RepeatedTest(50)
public void validateImages() {
void validateImages() {
CreateImageRequest createImageRequest = testDataUtil.randomCreateImageRequest();

Request request =
Expand All @@ -144,7 +144,7 @@ public void validateImages() {
}

@RepeatedTest(50)
public void validateModels() {
void validateModels() {
Model model = testDataUtil.randomModelObject();

Response response = createResponseWithBody(serializeObject(model));
Expand All @@ -153,7 +153,7 @@ public void validateModels() {
}

@RepeatedTest(50)
public void validateModerations() {
void validateModerations() {
ModerationRequest moderationRequest = testDataUtil.randomModerationRequest();

Request request =
Expand All @@ -168,7 +168,7 @@ public void validateModerations() {
}

@RepeatedTest(50)
public void validateAssistants() {
void validateAssistants() {
CreateAssistantRequest createAssistantRequest = testDataUtil.randomCreateAssistantRequest();

Request request =
Expand All @@ -185,7 +185,7 @@ public void validateAssistants() {
}

@RepeatedTest(50)
public void validateThreads() {
void validateThreads() {
CreateThreadRequest createThreadRequest = testDataUtil.randomCreateThreadRequest();

Request request =
Expand All @@ -210,7 +210,7 @@ public void validateThreads() {
}

@RepeatedTest(50)
public void validateMessages() {
void validateMessages() {
CreateMessageRequest createMessageRequest = testDataUtil.randomCreateMessageRequest();

Request request =
Expand All @@ -236,7 +236,7 @@ public void validateMessages() {
}

@RepeatedTest(50)
public void validateRuns() {
void validateRuns() {
// Comment out until https://github.com/openai/openai-openapi/pull/170 is merged
// CreateRunRequest createRunRequest = testDataUtil.randomCreateRunRequest();
//
Expand Down

0 comments on commit 29c42ad

Please sign in to comment.