milwright commited on
Commit
2f6bbd8
·
1 Parent(s): d339d89

improve: enhance contextual prompts with robust safety rules and year integration

Browse files

- Update AI prompts to prevent word revelation and improve educational quality
- Add year contextualization with "Published in {year}," prefix
- Strengthen safety rules to prevent variations like "Latinx" appearing
- Increase response flexibility while maintaining game integrity

src/clozeGameEngine.js CHANGED
@@ -250,6 +250,7 @@ class ClozeGame {
250
  passage: this.originalText,
251
  bookTitle: this.currentBook.title,
252
  author: this.currentBook.author,
 
253
  wordPosition: index,
254
  difficulty: this.calculateWordDifficulty(cleanWord, index, words)
255
  };
 
250
  passage: this.originalText,
251
  bookTitle: this.currentBook.title,
252
  author: this.currentBook.author,
253
+ year: this.currentBook.year,
254
  wordPosition: index,
255
  difficulty: this.calculateWordDifficulty(cleanWord, index, words)
256
  };
src/conversationManager.js CHANGED
@@ -25,6 +25,7 @@ class ChatService {
25
  fullPassage: wordData.passage,
26
  bookTitle: wordData.bookTitle,
27
  author: wordData.author,
 
28
  wordPosition: wordData.wordPosition,
29
  difficulty: wordData.difficulty,
30
  previousAttempts: [],
@@ -101,18 +102,19 @@ class ChatService {
101
 
102
  // Build focused prompt for specific question types
103
  buildFocusedPrompt(context, questionType, userInput) {
104
- const { sentence, bookTitle, author, targetWord } = context;
105
- const baseContext = `From "${bookTitle}" by ${author}: "${sentence}"`;
106
- const wordInstruction = `The target word is "${targetWord}". NEVER mention or reveal this word in your response.`;
 
107
 
108
  const prompts = {
109
- part_of_speech: `${baseContext}\n\n${wordInstruction}\n\nState only the grammatical category: "This is a noun" or "This is a verb" etc. Then give ONE grammar rule about how this type of word works. Maximum 15 words total.`,
110
 
111
- sentence_role: `${baseContext}\n\n${wordInstruction}\n\nExplain only what job "${targetWord}" does in this specific sentence. Focus on its function, not what it means. Start with "In this sentence, it..." Maximum 15 words.`,
112
 
113
- word_category: `${baseContext}\n\n${wordInstruction}\n\nClassify "${targetWord}" into a broad category. Choose from: living thing, object, action, feeling, quality, place, or time. Say "This belongs to the category of..." Maximum 12 words.`,
114
 
115
- synonym: `${baseContext}\n\n${wordInstruction}\n\nGive a different word that could replace "${targetWord}" in this sentence. Say "You could use the word..." Maximum 8 words. Choose a simple synonym.`
116
  };
117
 
118
  return prompts[questionType] || `${baseContext}\n\n${wordInstruction}\n\nProvide a helpful hint about "${targetWord}" without revealing it.`;
 
25
  fullPassage: wordData.passage,
26
  bookTitle: wordData.bookTitle,
27
  author: wordData.author,
28
+ year: wordData.year || null,
29
  wordPosition: wordData.wordPosition,
30
  difficulty: wordData.difficulty,
31
  previousAttempts: [],
 
102
 
103
  // Build focused prompt for specific question types
104
  buildFocusedPrompt(context, questionType, userInput) {
105
+ const { sentence, bookTitle, author, targetWord, year } = context;
106
+ const yearPrefix = year ? `Published in ${year}, ` : '';
107
+ const baseContext = `${yearPrefix}from "${bookTitle}" by ${author}: "${sentence}"`;
108
+ const safetyRule = `Important: The hidden word is "${targetWord}". Never say this word directly - use "it," "this word," or "the word" instead.`;
109
 
110
  const prompts = {
111
+ part_of_speech: `${baseContext}\n\n${safetyRule}\n\nIdentify the part of speech and share one interesting grammar tip about this type of word. Keep it conversational and under 25 words.\nExample: "It's a verb! These words show action or states of being, like 'run' or 'exist'."`,
112
 
113
+ sentence_role: `${baseContext}\n\n${safetyRule}\n\nExplain what role this word plays in the sentence - what's its job here? Be specific to THIS sentence. Keep it under 20 words and conversational.\nExample: "Here it connects two ideas, showing how one thing relates to another."`,
114
 
115
+ word_category: `${baseContext}\n\n${safetyRule}\n\nWhat general category does this word belong to? Think broadly - is it about people, things, actions, qualities, feelings, places, or ideas? Explain briefly in under 20 words.\nExample: "This word fits in the 'qualities' category - it describes how something looks or feels."`,
116
 
117
+ synonym: `${baseContext}\n\n${safetyRule}\n\nSuggest a word that could replace it in this sentence. Pick something simple and explain why it works. Under 15 words.\nExample: "You could use 'bright' here - it captures the same feeling of intensity."`
118
  };
119
 
120
  return prompts[questionType] || `${baseContext}\n\n${wordInstruction}\n\nProvide a helpful hint about "${targetWord}" without revealing it.`;