Skip to content

Commit f4d6224

Browse files
committed
updated prompt to have both source and target language
1 parent 394159d commit f4d6224

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

src/main/java/com/jakegodsall/services/prompt/PromptService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,25 @@ public interface PromptService {
2929
*
3030
* @param targetWord the word in the target language that will be used to generate the flashcard.
3131
* @param flashcardType the type of flashcard to generate, as defined by the {@link FlashcardType} enumeration (e.g., WORD, SENTENCE).
32-
* @param language the language in which the flashcard content will be generated.
32+
* @param sourceLanguage the language in which the flashcard content will be generated.
33+
* @param targetLanguage the language in which the flashcard content will be generated.
3334
* @param options additional options that influence the generation of the prompt, such as difficulty level or specific grammatical features.
3435
* @return the generated prompt as a {@code String}, which will be sent to the API.
3536
*/
36-
String generatePrompt(String targetWord, FlashcardType flashcardType, Language language, Options options);
37+
String generatePrompt(String targetWord, FlashcardType flashcardType, Language sourceLanguage, Language targetLanguage, Options options);
3738

3839
/**
3940
* Generates a prompt for multiple flashcards based on a single target word.
4041
*
4142
* @param targetWord the word in the target language that will be used to generate multiple flashcards.
4243
* @param flashcardType the type of flashcard to generate.
43-
* @param language the language in which the flashcard content will be generated.
44+
* @param sourceLanguage the language in which the flashcard content will be generated.
45+
* @param targetLanguage the language in which the flashcard content will be generated.
4446
* @param options additional options that influence the generation of the prompt.
4547
* @param count the number of flashcards to generate.
4648
* @return the generated prompt as a {@code String}, which will be sent to the API.
4749
*/
48-
String generatePromptForMultipleFlashcards(String targetWord, FlashcardType flashcardType, Language language, Options options, int count);
50+
String generatePromptForMultipleFlashcards(String targetWord, FlashcardType flashcardType, Language sourceLanguage, Language targetLanguage, Options options, int count);
4951

5052
/**
5153
* Creates a simple prompt for the next word in a sequence.

src/main/java/com/jakegodsall/services/prompt/impl/PromptServiceGPTImpl.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ public String generateRequestBody(String prompt) throws JsonProcessingException
3636
}
3737

3838
@Override
39-
public String generatePrompt(String targetWord, FlashcardType flashcardType, Language language, Options options) {
39+
public String generatePrompt(String targetWord, FlashcardType flashcardType, Language sourceLanguage, Language targetLanguage, Options options) {
4040
return generateBasePrompt() +
4141
getDescriptionOfContent(flashcardType) +
4242
getFlashcardStructure(flashcardType) +
43-
"The word is \"" + targetWord + "\" and the target language is " + language.getName() + ".\n" +
43+
"The word in the source language is \"" + targetWord + "\" and the target language is " + targetLanguage.getName() + ".\n" +
4444
getFormattingRules();
4545
}
4646

47-
@Override
48-
public String generatePromptForMultipleFlashcards(String targetWord, FlashcardType flashcardType, Language language, Options options, int count) {
47+
@Override
48+
public String generatePromptForMultipleFlashcards(String targetWord, FlashcardType flashcardType, Language sourceLanguage, Language targetLanguage, Options options, int count) {
4949
StringBuilder prompt = new StringBuilder();
5050

5151
// Initial warning about target word usage
@@ -54,6 +54,9 @@ public String generatePromptForMultipleFlashcards(String targetWord, FlashcardTy
5454
.append(targetWord)
5555
.append("\" in the native language sentences. Instead, use its translation or rephrase the sentence completely.\n\n");
5656
}
57+
58+
prompt.append("You are a language learning assistant.\n")
59+
.append("You are given a word in a target language and you need to generate flashcards for it.\n")
5760

5861
prompt.append("Generate ")
5962
.append(count)
@@ -64,23 +67,23 @@ public String generatePromptForMultipleFlashcards(String targetWord, FlashcardTy
6467
.append(getDescriptionOfContent(flashcardType))
6568
.append("The structure for each flashcard in the array should be:\n")
6669
.append(getFlashcardStructure(flashcardType))
67-
.append("The word is \"")
70+
.append("The word in the source language is \"")
6871
.append(targetWord)
6972
.append("\" and the target language is ")
70-
.append(language.getName())
73+
.append(targetLanguage.getName())
7174
.append(".\n");
7275

7376
if (flashcardType == FlashcardType.SENTENCE) {
7477
prompt.append("\nABSOLUTELY ESSENTIAL:\n")
7578
.append("1. The word \"")
7679
.append(targetWord)
7780
.append("\" MUST ONLY appear in the target language sentence\n")
78-
.append("2. The native language sentence MUST NOT contain \"")
81+
.append("2. The source language sentence MUST NOT contain \"")
7982
.append(targetWord)
8083
.append("\" - use its translation instead\n")
8184
.append("3. If you're tempted to use \"")
8285
.append(targetWord)
83-
.append("\" in the native sentence, STOP and rephrase it\n\n");
86+
.append("\" in the source sentence, STOP and rephrase it\n\n");
8487
}
8588

8689
prompt.append("Each flashcard should use different example sentences and translations while maintaining accuracy.\n")
@@ -119,11 +122,11 @@ private String getFlashcardStructure(FlashcardType flashcardType) {
119122

120123
private String getFormattingRules() {
121124
return "Please follow these formatting rules:\n" +
122-
"1. If the word is a verb in the infinitive form, prefix it with \"to \" in both native and target languages\n" +
123-
"2. The native word and target word should be in lowercase\n" +
125+
"1. If the word is a verb in the infinitive form, prefix it with \"to \" in both source and target languages\n" +
126+
"2. The source word and target word should be in lowercase\n" +
124127
"3. Example sentences must start with a capital letter and end with a period\n" +
125128
"4. Ensure proper sentence structure and punctuation in all example sentences\n" +
126-
"5. STRICT RULE FOR SENTENCE FLASHCARDS: The target word MUST NEVER appear in the native language sentence - ALWAYS use a translation or completely different phrasing\n" +
127-
"6. Double-check every native sentence to ensure it does not contain the target word in any form\n";
129+
"5. STRICT RULE FOR SENTENCE FLASHCARDS: The target word MUST NEVER appear in the source language sentence - ALWAYS use a translation or completely different phrasing\n" +
130+
"6. Double-check every source sentence to ensure it does not contain the target word in any form\n";
128131
}
129132
}

0 commit comments

Comments
 (0)