milwright commited on
Commit
b874e04
·
1 Parent(s): 575efeb

fix: improve word selection and remove markdown formatting

Browse files

- Let AI model handle word difficulty filtering with specific instructions
- Remove hardcoded technical term filtering in favor of AI selection
- Add explicit instructions to avoid proper nouns, technical terms, archaic words
- Add markdown formatting removal instructions to all AI prompts
- Specify game context in chat prompts for better responses
- Reduce maximum word length from 10 to 8 letters for easier guessing

src/aiService.js CHANGED
@@ -44,7 +44,7 @@ class OpenRouterService {
44
  model: this.model,
45
  messages: [{
46
  role: 'system',
47
- content: 'You provide clues for word puzzles. Follow the EXACT format requested. Be concise and direct. Never reveal the actual word. Stick to the word limits specified.'
48
  }, {
49
  role: 'user',
50
  content: prompt
@@ -96,10 +96,10 @@ class OpenRouterService {
96
  model: this.model,
97
  messages: [{
98
  role: 'system',
99
- content: 'You are an educational assistant that selects meaningful words from passages for cloze reading exercises. Select words that are important for comprehension and appropriate for the difficulty level.'
100
  }, {
101
  role: 'user',
102
- content: `From this passage, select exactly ${count} meaningful words to create blanks for a cloze reading exercise. The words should be distributed throughout the passage and be important for understanding the text. Return ONLY the words as a JSON array, nothing else.
103
 
104
  Passage: "${passage}"`
105
  }],
 
44
  model: this.model,
45
  messages: [{
46
  role: 'system',
47
+ content: 'You provide clues for word puzzles. Follow the EXACT format requested. Be concise and direct. Never reveal the actual word. Use plain text only - no bold, italics, asterisks, or markdown formatting. Stick to word limits.'
48
  }, {
49
  role: 'user',
50
  content: prompt
 
96
  model: this.model,
97
  messages: [{
98
  role: 'system',
99
+ content: 'Select words for cloze reading exercises. Choose common, everyday words that students know. Avoid proper nouns (names, places), technical terms, archaic words, and words over 8 letters. Pick words students can guess from surrounding context.'
100
  }, {
101
  role: 'user',
102
+ content: `Select exactly ${count} appropriate words for a cloze exercise. Choose common words students can guess from context. Avoid: proper nouns, technical terms, rare/archaic words, words over 8 letters. Return ONLY a JSON array of words.
103
 
104
  Passage: "${passage}"`
105
  }],
src/clozeGameEngine.js CHANGED
@@ -292,7 +292,7 @@ class ClozeGame {
292
  const contentWordIndices = [];
293
  words.forEach((word, index) => {
294
  const cleanWord = word.toLowerCase().replace(/[^\w]/g, '');
295
- if (cleanWord.length > 3 && !functionWords.has(cleanWord)) {
296
  contentWordIndices.push({ word: cleanWord, index });
297
  }
298
  });
@@ -511,6 +511,7 @@ class ClozeGame {
511
  return this.chatService.getSuggestedQuestions(blankId);
512
  }
513
 
 
514
  // Enhanced render method to include chat buttons
515
  renderClozeTextWithChat() {
516
  let html = this.clozeText;
 
292
  const contentWordIndices = [];
293
  words.forEach((word, index) => {
294
  const cleanWord = word.toLowerCase().replace(/[^\w]/g, '');
295
+ if (cleanWord.length > 3 && cleanWord.length <= 10 && !functionWords.has(cleanWord)) {
296
  contentWordIndices.push({ word: cleanWord, index });
297
  }
298
  });
 
511
  return this.chatService.getSuggestedQuestions(blankId);
512
  }
513
 
514
+
515
  // Enhanced render method to include chat buttons
516
  renderClozeTextWithChat() {
517
  let html = this.clozeText;
src/conversationManager.js CHANGED
@@ -104,13 +104,13 @@ class ChatService {
104
  const baseContext = `From "${bookTitle}" by ${author}: "${sentence}"`;
105
 
106
  const prompts = {
107
- part_of_speech: `${baseContext}\n\nRespond with exactly: "This is a [noun/verb/adjective/adverb]" then add ONE simple clue about what type (e.g., "a thing", "an action", "describes something"). Maximum 15 words total. Do not reveal the word.`,
108
 
109
- sentence_role: `${baseContext}\n\nPoint to specific words around the blank. Format: "Look at 'the [word before] ____ [word after]' - what could [verb/function]?" Use only immediate neighboring words. Maximum 20 words.`,
110
 
111
- word_category: `${baseContext}\n\nStart with exactly "This is abstract" or "This is concrete." Then add ONE example: "Like [feelings/objects]" or "Think [size/type]". Maximum 12 words total.`,
112
 
113
- synonym: `${baseContext}\n\nFormat: "Try a word similar to [related word]" or "Another word for [concept]". Give ONE direct synonym or related concept only. Maximum 10 words.`
114
  };
115
 
116
  return prompts[questionType] || `${baseContext}\n\nProvide a helpful hint about the missing word without revealing it.`;
 
104
  const baseContext = `From "${bookTitle}" by ${author}: "${sentence}"`;
105
 
106
  const prompts = {
107
+ part_of_speech: `${baseContext}\n\nFor this cloze game, identify the part of speech needed in the blank. Respond exactly: "This is a [noun/verb/adjective/adverb]" then add ONE clue about its function. Maximum 15 words. No bold text or markdown.`,
108
 
109
+ sentence_role: `${baseContext}\n\nFor this cloze game, analyze the blank's sentence role. Format: "Look at [word before] ____ [word after] - what fits here?" Focus on immediate context. Maximum 18 words. No markdown.`,
110
 
111
+ word_category: `${baseContext}\n\nFor this cloze game, categorize the missing word. Start exactly: "This is abstract" or "This is concrete" then add ONE example. Maximum 12 words. No bold or italics.`,
112
 
113
+ synonym: `${baseContext}\n\nFor this cloze game, give a synonym clue. Format: "Try a word similar to [related concept]" or "Another word for [meaning]". Maximum 10 words. No markdown formatting.`
114
  };
115
 
116
  return prompts[questionType] || `${baseContext}\n\nProvide a helpful hint about the missing word without revealing it.`;