diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java index 448b21b2a8..26c9ba4198 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/AIRepositoryLocaleOverrideCommand.java @@ -45,7 +45,7 @@ public class AIRepositoryLocaleOverrideCommand extends Command { names = {"--disabled"}, required = false, description = - "Indicates if the locales are disabled for AI translation. Setting to false means AI translation will be skipped for the relevant locales. Default is false") + "Indicates if the locales are disabled for AI translation. Setting to true means AI translation will be skipped for the relevant locales. Default is false") boolean disabled = false; @Parameter( diff --git a/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptCommand.java b/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptCommand.java index f2872dc0c5..1e365009b9 100644 --- a/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptCommand.java +++ b/cli/src/main/java/com/box/l10n/mojito/cli/command/CreateAIPromptCommand.java @@ -24,7 +24,7 @@ public class CreateAIPromptCommand extends Command { @Parameter( names = {"--repository-name", "-r"}, - required = true, + required = false, description = "Repository name") String repository; diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/ai/LLMPromptService.java b/webapp/src/main/java/com/box/l10n/mojito/service/ai/LLMPromptService.java index 3f8d1ca702..6437398d47 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/ai/LLMPromptService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/ai/LLMPromptService.java @@ -51,7 +51,11 @@ public class LLMPromptService implements PromptService { @Transactional public Long createPrompt(AIPromptCreateRequest AIPromptCreateRequest) { - Repository repository = getRepository(AIPromptCreateRequest.getRepositoryName()); + Repository repository = null; + if (AIPromptCreateRequest.getRepositoryName() != null + && !AIPromptCreateRequest.getRepositoryName().isEmpty()) { + repository = getRepository(AIPromptCreateRequest.getRepositoryName()); + } AIPromptType aiPromptType = aiPromptTypeRepository.findByName(AIPromptCreateRequest.getPromptType()); @@ -74,11 +78,18 @@ public Long createPrompt(AIPromptCreateRequest AIPromptCreateRequest) { aiPromptRepository.save(aiPrompt); logger.debug("Created prompt with id: {}", aiPrompt.getId()); - RepositoryLocaleAIPrompt repositoryLocaleAIPrompt = new RepositoryLocaleAIPrompt(); - repositoryLocaleAIPrompt.setRepository(repository); - repositoryLocaleAIPrompt.setAiPrompt(aiPrompt); - repositoryLocaleAIPromptRepository.save(repositoryLocaleAIPrompt); - logger.debug("Created repository prompt with id: {}", repositoryLocaleAIPrompt.getId()); + if (repository != null) { + RepositoryLocaleAIPrompt repositoryLocaleAIPrompt = + aiPromptType.getName().equals(PromptType.TRANSLATION.name()) + ? repositoryLocaleAIPromptRepository + .getRepositoryDefaultTranslationPrompt(repository) + .orElse(new RepositoryLocaleAIPrompt()) + : new RepositoryLocaleAIPrompt(); + repositoryLocaleAIPrompt.setRepository(repository); + repositoryLocaleAIPrompt.setAiPrompt(aiPrompt); + repositoryLocaleAIPromptRepository.save(repositoryLocaleAIPrompt); + logger.debug("Created repository prompt with id: {}", repositoryLocaleAIPrompt.getId()); + } return aiPrompt.getId(); } diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/ai/RepositoryLocaleAIPromptRepository.java b/webapp/src/main/java/com/box/l10n/mojito/service/ai/RepositoryLocaleAIPromptRepository.java index 6bd88052f6..32cdd2bf55 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/ai/RepositoryLocaleAIPromptRepository.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/ai/RepositoryLocaleAIPromptRepository.java @@ -34,4 +34,12 @@ List getActivePromptsByRepositoryAndPromptType( + "WHERE rlap.repository = :repository AND rlap.locale IS NOT NULL AND aipt.name = 'TRANSLATION'") Optional> getRepositoryLocaleTranslationPromptOverrides( @Param("repository") Repository repository); + + @Query( + "SELECT rlap from RepositoryLocaleAIPrompt rlap " + + "JOIN rlap.aiPrompt aip " + + "JOIN aip.promptType aipt " + + "WHERE rlap.repository = :repository AND rlap.locale IS NULL AND aipt.name = 'TRANSLATION'") + Optional getRepositoryDefaultTranslationPrompt( + @Param("repository") Repository repository); } diff --git a/webapp/src/test/java/com/box/l10n/mojito/service/ai/LLMPromptServiceTest.java b/webapp/src/test/java/com/box/l10n/mojito/service/ai/LLMPromptServiceTest.java index b121f62595..0d20128423 100644 --- a/webapp/src/test/java/com/box/l10n/mojito/service/ai/LLMPromptServiceTest.java +++ b/webapp/src/test/java/com/box/l10n/mojito/service/ai/LLMPromptServiceTest.java @@ -63,6 +63,7 @@ void testPromptCreation() { repositoryLocaleAIPrompt.setId(1L); AIPromptType promptType = new AIPromptType(); promptType.setId(1L); + promptType.setName("SOURCE_STRING_CHECKER"); AIPrompt prompt = new AIPrompt(); prompt.setId(1L); prompt.setUserPrompt("Check strings for spelling");