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 " ;
22const HF_TOKEN = "HF_TOKEN_PLACEHOLDER" ;
33
44let skillsData = [ ] ;
@@ -189,9 +189,7 @@ async function getAgentResponse(userMessage) {
189189INFORMACIÓ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
221220document . addEventListener ( 'DOMContentLoaded' , ( ) => {
0 commit comments