Miguel Diaz commited on
Commit
4b40455
·
1 Parent(s): 618c217

fix: Statics

Browse files
static/js/chatHandler.js CHANGED
@@ -1,6 +1,7 @@
1
  class ChatGPT{
2
  constructor(token){
3
 
 
4
 
5
  if (localStorage.getItem("convesacion") !== null) {
6
  this.convesacion = JSON.parse(localStorage.getItem("convesacion"));
@@ -18,12 +19,29 @@ class ChatGPT{
18
  };
19
  }
20
 
 
 
21
  this.endpointChat = "/chat_stream";
22
  this.token = token
23
  this.evCtx = document
 
 
 
 
 
 
 
 
 
24
 
25
- $(this.evCtx).on("chat:enviar", (event, params) => this.enviar(params));
26
-
 
 
 
 
 
 
27
 
28
  }
29
 
@@ -39,7 +57,7 @@ class ChatGPT{
39
  $(this.evCtx).trigger("enviar:cargando",mensaje);
40
 
41
  console.log("Cagados ", tokens, "tokens");
42
-
43
  $.ajax({
44
  type: "POST",
45
  url: this.endpointChat,
@@ -56,14 +74,21 @@ class ChatGPT{
56
  this.convesacion.push({role: "user", content: mensaje, tokens: data.input_tokens} )
57
  this.convesacion.push({role: data.role, content: data.content, tokens: data.output_tokens} )
58
  this.token = data.token;
 
59
  $(this.evCtx).trigger("enviar:exito", data);
60
  })
61
  .fail(( jqXHR, status, error ) => {
62
  console.log("enviado fallido")
63
  console.log(jqXHR)
 
64
  console.log(status)
65
  console.log(error)
66
- $(this.evCtx).trigger("enviar:error",{jqXHR:jqXHR, status:status, error:error});
 
 
 
 
 
67
  })
68
 
69
  }
 
1
  class ChatGPT{
2
  constructor(token){
3
 
4
+ $("#input-delete").click(()=> $(this.evCtx).trigger("chat:limpiar"))
5
 
6
  if (localStorage.getItem("convesacion") !== null) {
7
  this.convesacion = JSON.parse(localStorage.getItem("convesacion"));
 
19
  };
20
  }
21
 
22
+ this.execStart = 0;
23
+
24
  this.endpointChat = "/chat_stream";
25
  this.token = token
26
  this.evCtx = document
27
+ this.reintentos = 0
28
+ $(this.evCtx).on("chat:limpiar", () => limpiarConfig());
29
+ $(this.evCtx).on("chat:enviar", (event, params) => {
30
+ this.reintentos = 0;
31
+ this.enviar(params)
32
+ });
33
+ $(this.evCtx).on("enviar:error", (event, params) => this.enviar(params));
34
+
35
+ }
36
 
37
+ limpiarConfig(){
38
+ localStorage.removeItem('convesacion');
39
+ localStorage.removeItem('config');
40
+ this.config = {
41
+ temperature: 1.0,
42
+ frequency_penalty: 0.0,
43
+ presence_penalty: 0.0
44
+ };
45
 
46
  }
47
 
 
57
  $(this.evCtx).trigger("enviar:cargando",mensaje);
58
 
59
  console.log("Cagados ", tokens, "tokens");
60
+ this.execStart = performance.now()
61
  $.ajax({
62
  type: "POST",
63
  url: this.endpointChat,
 
74
  this.convesacion.push({role: "user", content: mensaje, tokens: data.input_tokens} )
75
  this.convesacion.push({role: data.role, content: data.content, tokens: data.output_tokens} )
76
  this.token = data.token;
77
+ data.execTime = performance.now() - this.execStart;
78
  $(this.evCtx).trigger("enviar:exito", data);
79
  })
80
  .fail(( jqXHR, status, error ) => {
81
  console.log("enviado fallido")
82
  console.log(jqXHR)
83
+ console.log(jqXHR.responseJSON.detail)
84
  console.log(status)
85
  console.log(error)
86
+ let execTime = performance.now() - this.execStart;
87
+ $(this.evCtx).trigger("enviar:error",{jqXHR:jqXHR, status:status, error:error, execTime:execTime, mensaje:mensaje});
88
+ if(this.reintentos++ < 3 && execTime < 1.0){
89
+ this.enviar(mensaje)
90
+ }
91
+
92
  })
93
 
94
  }
static/js/windowHandler.js CHANGED
@@ -8,7 +8,14 @@ class WindowHandler{
8
  $(this.evCtx).on("enviar:exito", (event, params) => this.procesarTexto(params));
9
  $(this.evCtx).on("chat:cargar", (event, params) => this.cargarChat(params));
10
  $(this.evCtx).on("chat:mostrar", (event, params) => this.cargarChat(params));
11
-
 
 
 
 
 
 
 
12
  }
13
 
14
  manejadorEnviar(){
 
8
  $(this.evCtx).on("enviar:exito", (event, params) => this.procesarTexto(params));
9
  $(this.evCtx).on("chat:cargar", (event, params) => this.cargarChat(params));
10
  $(this.evCtx).on("chat:mostrar", (event, params) => this.cargarChat(params));
11
+ $(this.evCtx).on("chat:enviar", (event, params) => this.recaularTextarea());
12
+ $(this.evCtx).on("chat:limpiar", () => limpiarChat());
13
+ }
14
+
15
+ limpiarChat(){
16
+ $("#input-text").val("");
17
+ recaularTextbox();
18
+ $("#chat").html("");
19
  }
20
 
21
  manejadorEnviar(){