Alfredo Villegas commited on
Commit
838ed10
2 Parent(s): 2d7d2cc 9f6a741

Merge remote-tracking branch 'chattest/main' into switch-button

Browse files
main.py CHANGED
@@ -81,6 +81,13 @@ async def root(request: Request, credentials: HTTPBasicCredentials = Depends(sec
81
  with open(os.path.join("static", "main.html")) as f:
82
  return HTMLResponse(f.read().replace("{% token %}", token).replace("{% version %}", fecha_unix))
83
 
 
 
 
 
 
 
 
84
 
85
  @app.post("/chat_stream")
86
  async def chat_stream(data = Depends(validate_token)):
 
81
  with open(os.path.join("static", "main.html")) as f:
82
  return HTMLResponse(f.read().replace("{% token %}", token).replace("{% version %}", fecha_unix))
83
 
84
+ @app.get("/tabs", response_class=HTMLResponse)
85
+ async def root_tabs(request: Request, credentials: HTTPBasicCredentials = Depends(security)):
86
+ if authenticate_user(credentials):
87
+ token = create_jwt_token({"user":credentials.username})
88
+ with open(os.path.join("static", "main2.html")) as f:
89
+ return HTMLResponse(f.read().replace("{% token %}", token).replace("{% version %}", fecha_unix))
90
+
91
 
92
  @app.post("/chat_stream")
93
  async def chat_stream(data = Depends(validate_token)):
static/css/app.css CHANGED
@@ -1,3 +1,5 @@
 
 
1
  html,
2
  body {
3
  margin: 0;
@@ -190,7 +192,7 @@ button{
190
  background-color: #ddd;
191
  background-repeat: no-repeat;
192
  background-position: center;
193
- border-left: solid 1px #555;
194
  }
195
  .input-box .input-send {
196
  background-image: url(/static/img/send.png);
@@ -204,12 +206,12 @@ button{
204
  .input-box button:last-child{
205
  border-radius: 0 5px 5px 0;
206
  }
207
- .input-box button:disabled, .input-box textarea:disabled{
208
  background-color: #8b8b8b;
209
  border-color: #8b8b8b;
210
-
211
  }
212
 
213
  #message-template{
214
  display: none;
215
- }
 
1
+ @import "switch.css";
2
+
3
  html,
4
  body {
5
  margin: 0;
 
192
  background-color: #ddd;
193
  background-repeat: no-repeat;
194
  background-position: center;
195
+ /* border-left: solid 1px #555; */
196
  }
197
  .input-box .input-send {
198
  background-image: url(/static/img/send.png);
 
206
  .input-box button:last-child{
207
  border-radius: 0 5px 5px 0;
208
  }
209
+ .input-box button:disabled, .input-box textarea:disabled, .input-box input:disabled{
210
  background-color: #8b8b8b;
211
  border-color: #8b8b8b;
212
+ filter: contrast(0.5);
213
  }
214
 
215
  #message-template{
216
  display: none;
217
+ }
static/css/app2.css ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .wrapper {
3
+ padding: 0px 20px 80px 20px !important;
4
+ border-bottom: 5px solid #222f3d;
5
+ background: #34495e;
6
+ margin: 0;
7
+ min-width: 320px;
8
+ width: 100%;
9
+ }
10
+
11
+ .tab {
12
+ overflow: hidden;
13
+ border: 1px solid #ccc;
14
+ background-color: #f1f1f1;
15
+ }
16
+
17
+ .tab button {
18
+ background-color: inherit;
19
+ float: left;
20
+ border: none;
21
+ outline: none;
22
+ cursor: pointer;
23
+ padding: 14px 16px;
24
+ transition: 0.3s;
25
+ }
26
+
27
+ .tab button:hover {
28
+ background-color: #ddd;
29
+ }
30
+
31
+ .tab button.active {
32
+ background-color: #ccc;
33
+ }
34
+
35
+ .tabcontent {
36
+ display: none;
37
+ padding: 6px 12px;
38
+ border: 1px solid #ccc;
39
+ border-top: none;
40
+ }
41
+
42
+ .tabcontent:first-child {
43
+ display: block;
44
+ }
45
+
46
+
47
+ .wrapper .tab {
48
+ overflow: hidden;
49
+ display: flex;
50
+ border-bottom: 1px solid #ccc;
51
+ background-color: #fff;
52
+ }
53
+
54
+ .wrapper .tab button {
55
+ background-color: transparent;
56
+ border: none;
57
+ outline: none;
58
+ cursor: pointer;
59
+ padding: 10px 15px;
60
+ font-size: 16px;
61
+ font-weight: bold;
62
+ color: #777;
63
+ transition: 0.3s;
64
+ }
65
+
66
+ .wrapper .tab button:hover {
67
+ background-color: #ddd;
68
+ }
69
+
70
+ .wrapper .tab button.active {
71
+ border-bottom: 2px solid #4285f4;
72
+ color: #4285f4;
73
+ }
74
+
75
+ /* Estilos para el contenido de los tabs */
76
+ .wrapper .tabcontent {
77
+ display: none;
78
+ padding: 20px;
79
+ border: 1px solid #ccc;
80
+ border-top: none;
81
+ }
82
+
83
+ .wrapper .tabcontent:first-child {
84
+ display: block;
85
+ }
static/css/switch.css ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Estilos del botón para google*/
2
+
3
+ .switch {
4
+ position: relative;
5
+ display: inline-block;
6
+ min-width: 54px;
7
+ max-width: 54px;
8
+ height: 30px;
9
+ margin: auto;
10
+ }
11
+
12
+ .switch input {
13
+ opacity: 0;
14
+ width: 0;
15
+ height: 0;
16
+ }
17
+
18
+ .slider {
19
+ position: absolute;
20
+ cursor: pointer;
21
+ top: 0;
22
+ left: 0;
23
+ right: 0;
24
+ bottom: 0;
25
+ background-color: #a1a1a1;
26
+ -webkit-transition: .4s;
27
+ transition: .4s;
28
+ }
29
+
30
+ .slider:before {
31
+ position: absolute;
32
+ content: "";
33
+ height: 23px;
34
+ width: 23px;
35
+ left: 4px;
36
+ bottom: 4px;
37
+ background: no-repeat center/80% url(https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/235px-Google_%22G%22_Logo.svg.png);
38
+ background-color: white;
39
+ -webkit-transition: .4s;
40
+ transition: .4s;
41
+ }
42
+
43
+ input:checked+.slider {
44
+ background-color: #3BBD96;
45
+ }
46
+
47
+ input:focus+.slider {
48
+ box-shadow: 0 0 1px #3BBD96;
49
+ }
50
+
51
+ input:checked+.slider:before {
52
+ -webkit-transform: translateX(23px);
53
+ -ms-transform: translateX(23px);
54
+ transform: translateX(23px);
55
+ box-shadow: 0 0 3px rgba(0, 0, 0, 5.5);
56
+ }
57
+
58
+ .slider.round {
59
+ border-radius: 34px;
60
+ }
61
+
62
+ .slider.round:before {
63
+ border-radius: 50%;
64
+ box-shadow: 0 0 3px rgba(0, 0, 0, 5.5);
65
+ background: no-repeat center/80% url(https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/235px-Google_%22G%22_Logo.svg.png);
66
+ background-color: white;
67
+ }
68
+
69
+ .switch:has(input:disabled) {
70
+ background: #8b8b8b;
71
+ filter: contrast(0.5);
72
+ }
static/js/chatHandler.js CHANGED
@@ -24,12 +24,11 @@ class ChatGPT{
24
  this.config = {
25
  temperature: 1.0,
26
  frequency_penalty: 0.0,
27
- presence_penalty: 0.0
 
28
  };
29
  }
30
-
31
  this.execStart = 0;
32
-
33
  this.endpointChat = "/chat_stream";
34
  this.token = token
35
  // this.evCtx = document
@@ -45,7 +44,12 @@ class ChatGPT{
45
  this.reintentos++;
46
  this.enviar(params.mensaje)
47
  });
48
-
 
 
 
 
 
49
  $(document).on("enviar:error", (event, params) => this.reenviar(params));
50
 
51
 
@@ -77,8 +81,11 @@ class ChatGPT{
77
  }
78
 
79
  enviar(mensaje){
 
80
  let tempMensajes = [];
81
  let tokens = 0;
 
 
82
  for(let i = 0; i < this.convesacion.length; i++){
83
  let actMsg = this.convesacion[i];
84
  tempMensajes.push({role: actMsg.role, content: actMsg.content})
 
24
  this.config = {
25
  temperature: 1.0,
26
  frequency_penalty: 0.0,
27
+ presence_penalty: 0.0,
28
+ googleSearch: false
29
  };
30
  }
 
31
  this.execStart = 0;
 
32
  this.endpointChat = "/chat_stream";
33
  this.token = token
34
  // this.evCtx = document
 
44
  this.reintentos++;
45
  this.enviar(params.mensaje)
46
  });
47
+ // Signaling
48
+ // los on se escuchan cuando suena lo que se està disparando.
49
+ $(document).on("accion:switch_change", (event, params) => {
50
+ this.config.googleSearch = params;
51
+ console.log(this.config);
52
+ })
53
  $(document).on("enviar:error", (event, params) => this.reenviar(params));
54
 
55
 
 
81
  }
82
 
83
  enviar(mensaje){
84
+ // Configuración de variables base
85
  let tempMensajes = [];
86
  let tokens = 0;
87
+
88
+ // Calculo de tokens y reconfiguración de mensajes para este caso
89
  for(let i = 0; i < this.convesacion.length; i++){
90
  let actMsg = this.convesacion[i];
91
  tempMensajes.push({role: actMsg.role, content: actMsg.content})
static/js/windowHandler.js CHANGED
@@ -1,4 +1,5 @@
1
  class WindowHandler{
 
2
  constructor(){
3
  this.chatbox = $("#chat");
4
  this.template = $('<div class="message"><div><p></p></div></div>');
@@ -18,6 +19,12 @@ class WindowHandler{
18
  $("#input-text").keypress(() => this.recalcularTextarea());
19
  $("#input-text").keyup(() => this.recalcularTextarea());
20
  $("#input-text").keydown(() => this.recalcularTextarea());
 
 
 
 
 
 
21
  this.cargarChat(chatH.convesacion);
22
 
23
  $(document).on("precarga:inicio", (event, params) => {
@@ -102,6 +109,7 @@ class WindowHandler{
102
  $("#input-text").val("");
103
  $("button").prop("disabled", true);
104
  $("textarea").prop("disabled", true);
 
105
  this.mensaje = ""
106
  let clone = this.template.clone();
107
  clone.addClass("me");
@@ -129,6 +137,7 @@ class WindowHandler{
129
  this.mensaje = "";
130
  $("button").prop("disabled", false);
131
  $("textarea").prop("disabled", false);
 
132
  $("textarea").focus();
133
  this.active.find("div p").html(msgProcesado);
134
  Prism.highlightAllUnder(this.active[0]);
@@ -156,7 +165,15 @@ class WindowHandler{
156
 
157
  }
158
 
159
-
160
-
161
-
162
- }
 
 
 
 
 
 
 
 
 
1
  class WindowHandler{
2
+ //en este se hacen los cambios visuales
3
  constructor(){
4
  this.chatbox = $("#chat");
5
  this.template = $('<div class="message"><div><p></p></div></div>');
 
19
  $("#input-text").keypress(() => this.recalcularTextarea());
20
  $("#input-text").keyup(() => this.recalcularTextarea());
21
  $("#input-text").keydown(() => this.recalcularTextarea());
22
+
23
+
24
+ $("#input-activar").change((event) => this.toggleSwitch(event));
25
+
26
+
27
+
28
  this.cargarChat(chatH.convesacion);
29
 
30
  $(document).on("precarga:inicio", (event, params) => {
 
109
  $("#input-text").val("");
110
  $("button").prop("disabled", true);
111
  $("textarea").prop("disabled", true);
112
+ $(".switch input").prop("disabled", true);
113
  this.mensaje = ""
114
  let clone = this.template.clone();
115
  clone.addClass("me");
 
137
  this.mensaje = "";
138
  $("button").prop("disabled", false);
139
  $("textarea").prop("disabled", false);
140
+ $(".switch input").prop("disabled", false);
141
  $("textarea").focus();
142
  this.active.find("div p").html(msgProcesado);
143
  Prism.highlightAllUnder(this.active[0]);
 
165
 
166
  }
167
 
168
+ toggleSwitch(event) {
169
+ //boton de switch para consultar con google.
170
+ let checkBox = event.currentTarget;
171
+ $(document).trigger("accion:switch_change", checkBox.checked);
172
+ if (checkBox.checked) {
173
+ console.log("Switch is turned on.");
174
+ } else {
175
+ console.log("Switch is turned off.");
176
+ }
177
+ }
178
+
179
+ }
static/main.html CHANGED
@@ -18,6 +18,10 @@
18
  <div class='input-box'>
19
  <textarea class='input-text' id='input-text' placeholder="Type something" type="text" autofocus=""></textarea>
20
  <button class='input-send' id='input-send' ></button>
 
 
 
 
21
  <button class='input-delete' id='input-delete' ></button>
22
  </div>
23
  </div>
 
18
  <div class='input-box'>
19
  <textarea class='input-text' id='input-text' placeholder="Type something" type="text" autofocus=""></textarea>
20
  <button class='input-send' id='input-send' ></button>
21
+ <label class="switch">
22
+ <input type="checkbox" id="input-activar">
23
+ <span class="slider round"></span>
24
+ </label>
25
  <button class='input-delete' id='input-delete' ></button>
26
  </div>
27
  </div>
static/main2.html ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <head>
3
+ <title> Chatbot </title>
4
+ <meta name="viewport" content="width=device-width">
5
+ <link rel="shortcut icon" href="static/favicon.png" type="image/png">
6
+ <link rel="stylesheet" href="static/css/app.css?v={% version %}">
7
+ <link rel="stylesheet" href="static/css/app2.css?v={% version %}">
8
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
9
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css" rel="stylesheet" />
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js" integrity="sha512-9khQRAUBYEJDCDVP2yw3LRUQvjJ0Pjx0EShmaQjcHa6AXiOv6qHQu9lCAIR8O+/D8FtaCoJ2c0Tf9Xo7hYH01Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js" integrity="sha512-SkmBfuA2hqjzEVpmnMt/LINrjop3GKWqsuLSSB3e7iBmYK7JuWw4ldmmxwD9mdm2IRTTi0OxSAfEGvgEi0i2Kw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
12
+ <script src="static/js/chatHandler.js?v={% version %}"></script>
13
+ <script src="static/js/windowHandler.js?v={% version %}"></script>
14
+
15
+ </head>
16
+ <body>
17
+
18
+ <div class="wrapper">
19
+ <div class="tab">
20
+ <button class="tablinks" onclick="openTab(event, 'tab1')">Tab 1</button>
21
+ <button class="tablinks" onclick="openTab(event, 'tab2')">Tab 2</button>
22
+ <button class="tablinks" onclick="openTab(event, 'tab3')">Tab 3</button>
23
+ </div>
24
+ <div id="tab1" class="tabcontent">
25
+ <div class="chat" id="chat1"></div>
26
+ <div class="input-box">
27
+ <textarea class="input-text" id="input-text1" placeholder="Type something" type="text" autofocus></textarea>
28
+ <button class="input-send" id="input-send1"></button>
29
+ <button class="input-delete" id="input-delete1"></button>
30
+ </div>
31
+ </div>
32
+ <div id="tab2" class="tabcontent">
33
+ <div class="chat" id="chat2"></div>
34
+ <div class="input-box">
35
+ <textarea class="input-text" id="input-text2" placeholder="Type something" type="text" autofocus></textarea>
36
+ <button class="input-send" id="input-send2"></button>
37
+ <button class="input-delete" id="input-delete2"></button>
38
+ </div>
39
+ </div>
40
+ <div id="tab3" class="tabcontent">
41
+ <div class="chat" id="chat3"></div>
42
+ <div class="input-box">
43
+ <textarea class="input-text" id="input-text3" placeholder="Type something" type="text" autofocus></textarea>
44
+ <button class="input-send" id="input-send3"></button>
45
+ <button class="input-delete" id="input-delete3"></button>
46
+ </div>
47
+ </div>
48
+ </div>
49
+
50
+
51
+
52
+ <script>
53
+ let windH = null;
54
+ let chatH = null;
55
+
56
+ $(document).ready(function() {
57
+ chatH = new ChatGPT("{% token %}");
58
+ windH = new WindowHandler();
59
+
60
+
61
+
62
+ });
63
+ function openTab(evt, tabName) {
64
+ var i, tabcontent, tablinks;
65
+
66
+ tabcontent = document.getElementsByClassName("tabcontent");
67
+ for (i = 0; i < tabcontent.length; i++) {
68
+ tabcontent[i].style.display = "none";
69
+ }
70
+
71
+ tablinks = document.getElementsByClassName("tablinks");
72
+ for (i = 0; i < tablinks.length; i++) {
73
+ tablinks[i].className = tablinks[i].className.replace(" active", "");
74
+ }
75
+
76
+ document.getElementById(tabName).style.display = "block";
77
+ evt.currentTarget.className += " active";
78
+ }
79
+ </script>
80
+ </body>
81
+ </html>