diff --git a/apps/opik-backend/src/main/java/com/comet/opik/domain/llmproviders/LlmProviderFactory.java b/apps/opik-backend/src/main/java/com/comet/opik/domain/llmproviders/LlmProviderFactory.java index 2d81f1412e..130a355197 100644 --- a/apps/opik-backend/src/main/java/com/comet/opik/domain/llmproviders/LlmProviderFactory.java +++ b/apps/opik-backend/src/main/java/com/comet/opik/domain/llmproviders/LlmProviderFactory.java @@ -17,6 +17,8 @@ @Singleton public class LlmProviderFactory { + public static final String ERROR_MODEL_NOT_SUPPORTED = "model not supported %s"; + private final LlmProviderClientConfig llmProviderClientConfig; private final LlmProviderApiKeyService llmProviderApiKeyService; @@ -52,7 +54,7 @@ private LlmProvider getLlmProvider(String model) { return LlmProvider.ANTHROPIC; } - throw new BadRequestException("model not supported: " + model); + throw new BadRequestException(ERROR_MODEL_NOT_SUPPORTED.formatted(model)); } /** diff --git a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ChatCompletionsResourceTest.java b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ChatCompletionsResourceTest.java index 426f895eed..b487b11f96 100644 --- a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ChatCompletionsResourceTest.java +++ b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ChatCompletionsResourceTest.java @@ -27,7 +27,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.NullSource; import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.clickhouse.ClickHouseContainer; import org.testcontainers.containers.MySQLContainer; @@ -41,6 +40,7 @@ import java.util.UUID; import java.util.stream.Stream; +import static com.comet.opik.domain.llmproviders.LlmProviderFactory.ERROR_MODEL_NOT_SUPPORTED; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assumptions.assumeThat; @@ -154,7 +154,6 @@ void createReturnsBadRequestWhenNoLlmProviderApiKey() { @ParameterizedTest @ValueSource(strings = {"", "non-existing-model"}) - @NullSource void createReturnsBadRequestWhenModelIsInvalid(String model) { var workspaceName = RandomStringUtils.randomAlphanumeric(20); var workspaceId = UUID.randomUUID().toString(); @@ -171,7 +170,7 @@ void createReturnsBadRequestWhenModelIsInvalid(String model) { assertThat(errorMessage.getCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST); assertThat(errorMessage.getMessage()) - .containsIgnoringCase("invalid model '%s'".formatted(model)); + .containsIgnoringCase(ERROR_MODEL_NOT_SUPPORTED.formatted(model)); } @ParameterizedTest