Spaces:
Sleeping
Sleeping
fix: provide target word to AI while preventing disclosure
Browse files- Include actual target word in prompts so AI gives accurate clues
- Add explicit instructions to never mention or reveal the word
- Update system prompt to clarify AI should know word but not disclose it
- Fixes issue where AI was guessing wrong word and giving incorrect clues
- src/aiService.js +1 -1
- src/conversationManager.js +11 -9
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
|
| 48 |
}, {
|
| 49 |
role: 'user',
|
| 50 |
content: prompt
|
|
|
|
| 44 |
model: this.model,
|
| 45 |
messages: [{
|
| 46 |
role: 'system',
|
| 47 |
+
content: 'You provide clues for word puzzles. You will be told the target word that players need to guess, but you must NEVER mention, spell, or reveal that word in your response. Follow the EXACT format requested. Be concise and direct about the target word without revealing it. Use plain text only - no bold, italics, asterisks, or markdown formatting. Stick to word limits.'
|
| 48 |
}, {
|
| 49 |
role: 'user',
|
| 50 |
content: prompt
|
src/conversationManager.js
CHANGED
|
@@ -74,14 +74,15 @@ class ChatService {
|
|
| 74 |
const bookTitle = context.bookTitle;
|
| 75 |
const author = context.author;
|
| 76 |
|
| 77 |
-
// Create sentence with blank
|
| 78 |
const sentenceWithBlank = sentence.replace(new RegExp(`\\b${word}\\b`, 'gi'), '____');
|
| 79 |
|
| 80 |
try {
|
| 81 |
-
// Build focused prompt
|
| 82 |
const prompt = this.buildFocusedPrompt({
|
| 83 |
...context,
|
| 84 |
-
sentence: sentenceWithBlank
|
|
|
|
| 85 |
}, questionType, userInput);
|
| 86 |
|
| 87 |
// Use the AI service as a simple API wrapper
|
|
@@ -100,20 +101,21 @@ class ChatService {
|
|
| 100 |
|
| 101 |
// Build focused prompt for specific question types
|
| 102 |
buildFocusedPrompt(context, questionType, userInput) {
|
| 103 |
-
const { sentence, bookTitle, author } = context;
|
| 104 |
const baseContext = `From "${bookTitle}" by ${author}: "${sentence}"`;
|
|
|
|
| 105 |
|
| 106 |
const prompts = {
|
| 107 |
-
part_of_speech: `${baseContext}\n\
|
| 108 |
|
| 109 |
-
sentence_role: `${baseContext}\n\
|
| 110 |
|
| 111 |
-
word_category: `${baseContext}\n\nWhat category does
|
| 112 |
|
| 113 |
-
synonym: `${baseContext}\n\nGive a conceptual hint. Format: "Think of something that [general description
|
| 114 |
};
|
| 115 |
|
| 116 |
-
return prompts[questionType] || `${baseContext}\n\nProvide a helpful hint about
|
| 117 |
}
|
| 118 |
|
| 119 |
// Simple fallback responses
|
|
|
|
| 74 |
const bookTitle = context.bookTitle;
|
| 75 |
const author = context.author;
|
| 76 |
|
| 77 |
+
// Create sentence with blank for context, but tell AI the actual word
|
| 78 |
const sentenceWithBlank = sentence.replace(new RegExp(`\\b${word}\\b`, 'gi'), '____');
|
| 79 |
|
| 80 |
try {
|
| 81 |
+
// Build focused prompt that includes the target word but forbids revealing it
|
| 82 |
const prompt = this.buildFocusedPrompt({
|
| 83 |
...context,
|
| 84 |
+
sentence: sentenceWithBlank,
|
| 85 |
+
targetWord: word
|
| 86 |
}, questionType, userInput);
|
| 87 |
|
| 88 |
// Use the AI service as a simple API wrapper
|
|
|
|
| 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\nGive the part of speech for "${targetWord}" and a grammatical hint. Say "This is a [noun/verb/adjective/adverb]" then explain its function. Maximum 20 words. Do not reveal the actual word.`,
|
| 110 |
|
| 111 |
+
sentence_role: `${baseContext}\n\n${wordInstruction}\n\nDescribe the role "${targetWord}" plays in this sentence. Does it express action, emotion, description, or relationship? Maximum 20 words. Do not reveal the actual word.`,
|
| 112 |
|
| 113 |
+
word_category: `${baseContext}\n\n${wordInstruction}\n\nWhat category does "${targetWord}" belong to? Say "This word describes [general category]" without giving specific examples. Maximum 20 words. Do not reveal the actual word.`,
|
| 114 |
|
| 115 |
+
synonym: `${baseContext}\n\n${wordInstruction}\n\nGive a conceptual hint about "${targetWord}". Format: "Think of something that [general description]." Be indirect and conceptual. Maximum 20 words. Do not reveal the actual word.`
|
| 116 |
};
|
| 117 |
|
| 118 |
+
return prompts[questionType] || `${baseContext}\n\n${wordInstruction}\n\nProvide a helpful hint about "${targetWord}" without revealing it.`;
|
| 119 |
}
|
| 120 |
|
| 121 |
// Simple fallback responses
|