Spaces:
Sleeping
Sleeping
fix: replace tool-calling with simple direct prompts like main branch
Browse files- src/aiService.js +11 -42
src/aiService.js
CHANGED
|
@@ -80,22 +80,12 @@ class OpenRouterService {
|
|
| 80 |
}
|
| 81 |
|
| 82 |
try {
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
// Create sophisticated tool-calling prompt
|
| 91 |
-
const systemPrompt = `You are an educational reading tutor using structured responses. You must respond using the provided tool to give focused, helpful hints without revealing the answer directly.
|
| 92 |
-
|
| 93 |
-
Context: This is from "${bookTitle}" - classic literature requiring thoughtful analysis.
|
| 94 |
-
|
| 95 |
-
Current word to help with: "${word}"
|
| 96 |
-
Sentence context: "${sentence}"
|
| 97 |
-
|
| 98 |
-
Use the ${tool.name} tool to provide an appropriate educational hint.`;
|
| 99 |
|
| 100 |
const response = await fetch(this.apiUrl, {
|
| 101 |
method: 'POST',
|
|
@@ -109,17 +99,13 @@ Use the ${tool.name} tool to provide an appropriate educational hint.`;
|
|
| 109 |
model: this.model,
|
| 110 |
messages: [{
|
| 111 |
role: 'system',
|
| 112 |
-
content:
|
| 113 |
}, {
|
| 114 |
role: 'user',
|
| 115 |
-
content: `Help me understand the word that fits in this context
|
| 116 |
-
}],
|
| 117 |
-
tools: [{
|
| 118 |
-
type: 'function',
|
| 119 |
-
function: tool
|
| 120 |
}],
|
| 121 |
-
max_tokens:
|
| 122 |
-
temperature: 0.
|
| 123 |
})
|
| 124 |
});
|
| 125 |
|
|
@@ -128,24 +114,7 @@ Use the ${tool.name} tool to provide an appropriate educational hint.`;
|
|
| 128 |
}
|
| 129 |
|
| 130 |
const data = await response.json();
|
| 131 |
-
|
| 132 |
-
// Extract tool call response
|
| 133 |
-
const message = data.choices[0].message;
|
| 134 |
-
if (message.tool_calls && message.tool_calls.length > 0) {
|
| 135 |
-
const toolCall = message.tool_calls[0];
|
| 136 |
-
if (toolCall.function && toolCall.function.arguments) {
|
| 137 |
-
try {
|
| 138 |
-
const args = JSON.parse(toolCall.function.arguments);
|
| 139 |
-
return args.hint || this.getEnhancedFallback(questionType, word, sentence, bookTitle);
|
| 140 |
-
} catch (parseError) {
|
| 141 |
-
console.warn('Failed to parse tool call arguments:', parseError);
|
| 142 |
-
}
|
| 143 |
-
}
|
| 144 |
-
}
|
| 145 |
-
|
| 146 |
-
// Fallback to message content if tool call failed
|
| 147 |
-
return message.content?.trim() || this.getEnhancedFallback(questionType, word, sentence, bookTitle);
|
| 148 |
-
|
| 149 |
} catch (error) {
|
| 150 |
console.error('Error generating contextual hint:', error);
|
| 151 |
return this.getEnhancedFallback(questionType, word, sentence, bookTitle);
|
|
|
|
| 80 |
}
|
| 81 |
|
| 82 |
try {
|
| 83 |
+
const prompts = {
|
| 84 |
+
part_of_speech: `What part of speech is the word in this blank in: "${sentence}"? Provide a clear, direct answer.`,
|
| 85 |
+
sentence_role: `What grammatical role does the word in this blank play in: "${sentence}"? Focus on its function.`,
|
| 86 |
+
word_category: `Is the word in this blank an abstract or concrete noun? Explain briefly with an example.`,
|
| 87 |
+
synonym: `What's a good synonym for the word that would fit in this blank: "${sentence}"?`
|
| 88 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
const response = await fetch(this.apiUrl, {
|
| 91 |
method: 'POST',
|
|
|
|
| 99 |
model: this.model,
|
| 100 |
messages: [{
|
| 101 |
role: 'system',
|
| 102 |
+
content: 'You are a helpful reading tutor. Provide clear, educational answers that help students learn without giving away the answer directly.'
|
| 103 |
}, {
|
| 104 |
role: 'user',
|
| 105 |
+
content: prompts[questionType] || `Help me understand the word that fits in this context: "${sentence}"`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
}],
|
| 107 |
+
max_tokens: 150,
|
| 108 |
+
temperature: 0.7
|
| 109 |
})
|
| 110 |
});
|
| 111 |
|
|
|
|
| 114 |
}
|
| 115 |
|
| 116 |
const data = await response.json();
|
| 117 |
+
return data.choices[0].message.content.trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
} catch (error) {
|
| 119 |
console.error('Error generating contextual hint:', error);
|
| 120 |
return this.getEnhancedFallback(questionType, word, sentence, bookTitle);
|