Spaces:
Running
Running
Miguel Diaz
commited on
Commit
•
f279b13
1
Parent(s):
1b7b519
dev: prueba
Browse files- static/js/chatHandler.js +24 -25
static/js/chatHandler.js
CHANGED
@@ -27,7 +27,7 @@ class ChatGPT{
|
|
27 |
presence_penalty: 0.0
|
28 |
};
|
29 |
}
|
30 |
-
|
31 |
this.execStart = 0;
|
32 |
|
33 |
this.endpointChat = "/chat_stream";
|
@@ -68,7 +68,7 @@ class ChatGPT{
|
|
68 |
$(document).trigger("enviar:fallido",{jqXHR:params.jqXHR, status:params.status, error:params.error, execTime:params.execTime, mensaje:params.mensaje});
|
69 |
return
|
70 |
}
|
71 |
-
if(this.
|
72 |
$(document).trigger("enviar:reintentar",{jqXHR:params.jqXHR, status:params.status, error:params.error, execTime:params.execTime, mensaje:params.mensaje});
|
73 |
$(document).trigger("enviar:enviar",{jqXHR:params.jqXHR, status:params.status, error:params.error, execTime:params.execTime, mensaje:params.mensaje});
|
74 |
|
@@ -113,16 +113,16 @@ class ChatGPT{
|
|
113 |
function push() {
|
114 |
reader.read().then(({done, value}) => {
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
if(done){
|
117 |
controller.close();
|
118 |
-
|
119 |
-
$(document).trigger("precarga:fin");
|
120 |
-
localStorage.setItem("convesacion", JSON.stringify(self.convesacion))
|
121 |
-
console.log("terminado", self.convesacion[self.convesacion.length-1].content)
|
122 |
-
}else{
|
123 |
-
this.convesacion.pop()
|
124 |
-
console.log("terminado con errores")
|
125 |
-
}
|
126 |
return
|
127 |
}
|
128 |
|
@@ -136,23 +136,21 @@ class ChatGPT{
|
|
136 |
|
137 |
data =JSON.parse((i>0?"{":"") + data + (i<elLen-1?"}":""));
|
138 |
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
}
|
151 |
}
|
152 |
-
}else{
|
153 |
-
$(document).trigger("precarga:error", {status: rstat, mensaje: data.detail});
|
154 |
}
|
155 |
|
|
|
156 |
}
|
157 |
push();
|
158 |
})
|
@@ -161,7 +159,8 @@ class ChatGPT{
|
|
161 |
push();
|
162 |
},
|
163 |
});
|
164 |
-
}).then(
|
|
|
165 |
}).catch(err =>{
|
166 |
console.log('Solicitud fallida', err)
|
167 |
});
|
|
|
27 |
presence_penalty: 0.0
|
28 |
};
|
29 |
}
|
30 |
+
this.retries = 0;
|
31 |
this.execStart = 0;
|
32 |
|
33 |
this.endpointChat = "/chat_stream";
|
|
|
68 |
$(document).trigger("enviar:fallido",{jqXHR:params.jqXHR, status:params.status, error:params.error, execTime:params.execTime, mensaje:params.mensaje});
|
69 |
return
|
70 |
}
|
71 |
+
if(this.retries < 3 ){
|
72 |
$(document).trigger("enviar:reintentar",{jqXHR:params.jqXHR, status:params.status, error:params.error, execTime:params.execTime, mensaje:params.mensaje});
|
73 |
$(document).trigger("enviar:enviar",{jqXHR:params.jqXHR, status:params.status, error:params.error, execTime:params.execTime, mensaje:params.mensaje});
|
74 |
|
|
|
113 |
function push() {
|
114 |
reader.read().then(({done, value}) => {
|
115 |
|
116 |
+
if(rstat != 200){
|
117 |
+
controller.close();
|
118 |
+
// this.convesacion.pop()
|
119 |
+
console.log("ERROOOOOOOORRRRROOORRROOOR")
|
120 |
+
$(document).trigger("precarga:error", {status: rstat, mensaje: data.detail});
|
121 |
+
}
|
122 |
+
|
123 |
if(done){
|
124 |
controller.close();
|
125 |
+
console.log("terminado con errores")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
return
|
127 |
}
|
128 |
|
|
|
136 |
|
137 |
data =JSON.parse((i>0?"{":"") + data + (i<elLen-1?"}":""));
|
138 |
|
139 |
+
|
140 |
+
if(data.object == "chat.token"){
|
141 |
+
self.token = data.token;
|
142 |
+
}else if(data.choices[0].hasOwnProperty("delta")){
|
143 |
+
let temp = data.choices[0].delta;
|
144 |
+
let key = Object.keys(temp)[0];
|
145 |
+
let elActual = self.convesacion[self.convesacion.length-1]
|
146 |
+
if(!elActual.hasOwnProperty(key)){elActual[key]="";}
|
147 |
+
elActual[key] += temp[key]
|
148 |
+
if(elActual.hasOwnProperty("content") && temp.content){
|
149 |
+
$(document).trigger("precarga:mensaje", temp.content);
|
|
|
150 |
}
|
|
|
|
|
151 |
}
|
152 |
|
153 |
+
|
154 |
}
|
155 |
push();
|
156 |
})
|
|
|
159 |
push();
|
160 |
},
|
161 |
});
|
162 |
+
}).then(err => {
|
163 |
+
console.log('Solicitud fallida', err)
|
164 |
}).catch(err =>{
|
165 |
console.log('Solicitud fallida', err)
|
166 |
});
|