Skip to content

Commit

Permalink
Make repository optional parameter in prompt creation command
Browse files Browse the repository at this point in the history
  • Loading branch information
maallen committed Nov 14, 2024
1 parent c446d2d commit 31babd2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CreateAIPromptCommand extends Command {

@Parameter(
names = {"--repository-name", "-r"},
required = true,
required = false,
description = "Repository name")
String repository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ List<RepositoryLocaleAIPrompt> getActivePromptsByRepositoryAndPromptType(
+ "WHERE rlap.repository = :repository AND rlap.locale IS NOT NULL AND aipt.name = 'TRANSLATION'")
Optional<List<RepositoryLocaleAIPrompt>> 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<RepositoryLocaleAIPrompt> getRepositoryDefaultTranslationPrompt(
@Param("repository") Repository repository);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 31babd2

Please sign in to comment.