Skip to content

Commit 4101e8b

Browse files
committed
Fix: Use new HuggingFace router API endpoint
1 parent d0059bf commit 4101e8b

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

script.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const HF_API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2";
1+
const HF_API_URL = "https://router.huggingface.co/mistralai/Mistral-7B-Instruct-v0.2/v1/chat/completions";
22
const HF_TOKEN = "HF_TOKEN_PLACEHOLDER";
33

44
let skillsData = [];
@@ -189,9 +189,7 @@ async function getAgentResponse(userMessage) {
189189
INFORMACIÓN DE RETOS DISPONIBLES:
190190
${skillsContext}
191191
192-
PREGUNTA DEL ESTUDIANTE: ${userMessage}
193-
194-
RESPUESTA:`;
192+
PREGUNTA DEL ESTUDIANTE: ${userMessage}`;
195193

196194
const response = await fetch(HF_API_URL, {
197195
headers: {
@@ -200,22 +198,23 @@ RESPUESTA:`;
200198
},
201199
method: 'POST',
202200
body: JSON.stringify({
203-
inputs: fullPrompt,
204-
parameters: {
205-
max_new_tokens: 300,
206-
temperature: 0.7,
207-
top_p: 0.9,
208-
return_full_text: false
209-
}
201+
messages: [
202+
{ role: "system", content: SYSTEM_PROMPT },
203+
{ role: "system", content: "INFORMACIÓN DE RETOS DISPONIBLES:\n" + skillsContext },
204+
{ role: "user", content: userMessage }
205+
],
206+
max_tokens: 300,
207+
temperature: 0.7
210208
})
211209
});
212210

213211
if (!response.ok) {
214-
throw new Error('API request failed');
212+
const errorText = await response.text();
213+
throw new Error('API request failed: ' + errorText);
215214
}
216215

217216
const result = await response.json();
218-
return result[0].generated_text || 'Lo siento, no pude generar una respuesta.';
217+
return result.choices?.[0]?.message?.content || result[0]?.generated_text || 'Lo siento, no pude generar una respuesta.';
219218
}
220219

221220
document.addEventListener('DOMContentLoaded', () => {

0 commit comments

Comments
 (0)