Hansimov commited on
Commit
077080c
1 Parent(s): 02acd51

:gem: [Feature] Separate Send and Regenerate, and bind enter event to send

Browse files
apps/llm_mixer/index.html CHANGED
@@ -12,8 +12,7 @@
12
  </head>
13
  <body>
14
  <div class="container">
15
- <div id="messagers-container" class="container mt-3">
16
- </div>
17
  <div id="user-interactions" class="container fixed-bottom mb-3">
18
  <div class="mt-2">
19
  <div class="col-auto">
 
12
  </head>
13
  <body>
14
  <div class="container">
15
+ <div id="messagers-container" class="container mt-3"></div>
 
16
  <div id="user-interactions" class="container fixed-bottom mb-3">
17
  <div class="mt-2">
18
  <div class="col-auto">
apps/llm_mixer/js/buttons_binder.js CHANGED
@@ -1,4 +1,5 @@
1
  import { ChatCompletionsRequester } from "./llm_requester.js";
 
2
 
3
  export class ButtonsBinder {
4
  constructor() {
@@ -12,50 +13,74 @@ export class ButtonsBinder {
12
 
13
  $("#user-input").keypress(async (event) => {
14
  let status = button.text().trim();
15
- if (
16
- event.key === "Enter" &&
17
- !event.shiftKey &&
18
- (status === "Send" || status === "Regenerate")
19
- ) {
20
  event.preventDefault();
21
- await this.handle_user_input(button);
22
  }
23
  });
24
  }
25
  async handle_user_input(button) {
 
 
 
 
26
  let status = button.text().trim();
27
- if (status === "Send" || status === "Regenerate") {
28
- console.log("Send");
29
- button
30
- .text("Stop")
31
- .removeClass("btn-primary btn-success")
32
- .addClass("btn-warning");
33
- await this.post_user_input();
34
- button
35
- .text("Regenerate")
36
- .removeClass("btn-warning")
37
- .addClass("btn-success")
38
- .attr("disabled", false);
39
  } else if (status === "Stop") {
40
- console.log("Stop");
41
- this.requester.stop();
42
- button
43
- .attr("disabled", true)
44
- .removeClass("btn-warning")
45
- .addClass("btn-success")
46
- .text("Regenerate")
47
- .attr("disabled", false);
48
  return;
49
  } else {
50
  console.log("No action");
51
  }
52
  }
 
53
  async post_user_input() {
54
  let user_input_content = $("#user-input").val();
55
  console.log(user_input_content);
56
  this.requester = new ChatCompletionsRequester(user_input_content);
57
  await this.requester.post();
58
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  bind() {
60
  this.bind_send_user_input();
61
  }
 
1
  import { ChatCompletionsRequester } from "./llm_requester.js";
2
+ import { pop_messager } from "./chat_operator.js";
3
 
4
  export class ButtonsBinder {
5
  constructor() {
 
13
 
14
  $("#user-input").keypress(async (event) => {
15
  let status = button.text().trim();
16
+ if (event.key === "Enter" && !event.shiftKey && status !== "Stop") {
 
 
 
 
17
  event.preventDefault();
18
+ await this.send(button);
19
  }
20
  });
21
  }
22
  async handle_user_input(button) {
23
+ let user_input_content = $("#user-input").val();
24
+ if (user_input_content === "") {
25
+ return;
26
+ }
27
  let status = button.text().trim();
28
+ if (status === "Send") {
29
+ this.send(button);
30
+ } else if (status === "Regenerate") {
31
+ this.regenerate(button);
 
 
 
 
 
 
 
 
32
  } else if (status === "Stop") {
33
+ this.stop(button);
 
 
 
 
 
 
 
34
  return;
35
  } else {
36
  console.log("No action");
37
  }
38
  }
39
+
40
  async post_user_input() {
41
  let user_input_content = $("#user-input").val();
42
  console.log(user_input_content);
43
  this.requester = new ChatCompletionsRequester(user_input_content);
44
  await this.requester.post();
45
  }
46
+
47
+ async send(button) {
48
+ console.log("Send");
49
+ button
50
+ .text("Stop")
51
+ .removeClass("btn-primary btn-success")
52
+ .addClass("btn-warning");
53
+ await this.post_user_input();
54
+ button
55
+ .text("Regenerate")
56
+ .removeClass("btn-warning")
57
+ .addClass("btn-success")
58
+ .attr("disabled", false);
59
+ }
60
+ async regenerate(button) {
61
+ console.log("Regenerate");
62
+ button
63
+ .text("Stop")
64
+ .removeClass("btn-primary btn-success")
65
+ .addClass("btn-warning");
66
+ pop_messager(2);
67
+ await this.post_user_input();
68
+ button
69
+ .text("Regenerate")
70
+ .removeClass("btn-warning")
71
+ .addClass("btn-success")
72
+ .attr("disabled", false);
73
+ }
74
+ async stop(button) {
75
+ console.log("Stop");
76
+ this.requester.stop();
77
+ button
78
+ .attr("disabled", true)
79
+ .removeClass("btn-warning")
80
+ .addClass("btn-success")
81
+ .text("Regenerate")
82
+ .attr("disabled", false);
83
+ }
84
  bind() {
85
  this.bind_send_user_input();
86
  }
apps/llm_mixer/js/chat_operator.js CHANGED
@@ -32,6 +32,10 @@ export function get_request_messages() {
32
  return messager_list.get_request_messages();
33
  }
34
 
 
 
 
 
35
  export function update_message(json_chunks, message_viewer = null) {
36
  if (message_viewer === null) {
37
  message_viewer = get_latest_message_viewer();
 
32
  return messager_list.get_request_messages();
33
  }
34
 
35
+ export function pop_messager(n = 2) {
36
+ return messager_list.pop(n);
37
+ }
38
+
39
  export function update_message(json_chunks, message_viewer = null) {
40
  if (message_viewer === null) {
41
  message_viewer = get_latest_message_viewer();