Spaces:
Sleeping
Sleeping
improve: implement better prompt engineering with word concealment and simplified hints
Browse files- src/conversationManager.js +8 -13
src/conversationManager.js
CHANGED
@@ -94,24 +94,23 @@ class ChatService {
|
|
94 |
console.warn('AI response failed:', error);
|
95 |
}
|
96 |
|
97 |
-
// Fallback - return
|
98 |
-
|
99 |
-
return fallback.response;
|
100 |
}
|
101 |
|
102 |
-
// Build focused prompt for specific question types
|
103 |
buildFocusedPrompt(context, questionType, userInput) {
|
104 |
const { sentence, bookTitle, author } = context;
|
105 |
const baseContext = `From "${bookTitle}" by ${author}: "${sentence}"`;
|
106 |
|
107 |
const prompts = {
|
108 |
-
part_of_speech: `${baseContext}\n\
|
109 |
|
110 |
-
sentence_role: `${baseContext}\n\
|
111 |
|
112 |
-
word_category: `${baseContext}\n\
|
113 |
|
114 |
-
synonym: `${baseContext}\n\
|
115 |
};
|
116 |
|
117 |
return prompts[questionType] || `${baseContext}\n\nProvide a helpful hint about the missing word without revealing it.`;
|
@@ -126,11 +125,7 @@ class ChatService {
|
|
126 |
synonym: "What other word could fit in this same spot with similar meaning?"
|
127 |
};
|
128 |
|
129 |
-
return
|
130 |
-
success: true,
|
131 |
-
response: fallbacks[questionType] || "Consider the context and what word would make sense here.",
|
132 |
-
questionType: questionType
|
133 |
-
};
|
134 |
}
|
135 |
|
136 |
|
|
|
94 |
console.warn('AI response failed:', error);
|
95 |
}
|
96 |
|
97 |
+
// Fallback - return simple fallback response
|
98 |
+
return this.getSimpleFallback(context, questionType);
|
|
|
99 |
}
|
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\nWhat type of word fits in the blank? Say "This is a [noun/verb/adjective/adverb]" then give a grammatical hint about its function. Maximum 20 words. Never reveal the word.`,
|
108 |
|
109 |
+
sentence_role: `${baseContext}\n\nWhat meaning role does the blank serve? Does it express action, emotion, description, or relationship? Maximum 20 words.`,
|
110 |
|
111 |
+
word_category: `${baseContext}\n\nWhat category does this word belong to? Say "This word describes [general category]" without giving specific examples. Maximum 20 words.`,
|
112 |
|
113 |
+
synonym: `${baseContext}\n\nGive a conceptual hint. Format: "Think of something that [general description of concept]." Be indirect and conceptual. Maximum 20 words.`
|
114 |
};
|
115 |
|
116 |
return prompts[questionType] || `${baseContext}\n\nProvide a helpful hint about the missing word without revealing it.`;
|
|
|
125 |
synonym: "What other word could fit in this same spot with similar meaning?"
|
126 |
};
|
127 |
|
128 |
+
return fallbacks[questionType] || "Consider the context and what word would make sense here.";
|
|
|
|
|
|
|
|
|
129 |
}
|
130 |
|
131 |
|