:recycle: [Refactor] Hid console log, and move stop stage
Browse files- components/buttons_binder.js +19 -18
 - components/chat_operator.js +2 -2
 
    	
        components/buttons_binder.js
    CHANGED
    
    | 
         @@ -10,7 +10,7 @@ import { setup_available_models_on_select } from "./llm_models_loader.js"; 
     | 
|
| 10 | 
         
             
            import { screen_scroller } from "../storage/states.js";
         
     | 
| 11 | 
         | 
| 12 | 
         
             
            export class ButtonsBinder {
         
     | 
| 13 | 
         
            -
                constructor() { 
     | 
| 14 | 
         
             
                bind() {
         
     | 
| 15 | 
         
             
                    let send_user_input_binder = new SendUserInputButtonBinder();
         
     | 
| 16 | 
         
             
                    send_user_input_binder.bind();
         
     | 
| 
         @@ -69,6 +69,15 @@ class SendUserInputButtonBinder { 
     | 
|
| 69 | 
         
             
                    }
         
     | 
| 70 | 
         
             
                }
         
     | 
| 71 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 72 | 
         
             
                async post_user_input() {
         
     | 
| 73 | 
         
             
                    let user_input_content = $("#user-input").val();
         
     | 
| 74 | 
         
             
                    console.log(user_input_content);
         
     | 
| 
         @@ -76,20 +85,12 @@ class SendUserInputButtonBinder { 
     | 
|
| 76 | 
         
             
                    this.requester.create_messager_components();
         
     | 
| 77 | 
         
             
                    start_latest_message_animation();
         
     | 
| 78 | 
         
             
                    await this.requester.post();
         
     | 
| 
         | 
|
| 79 | 
         
             
                }
         
     | 
| 80 | 
         | 
| 81 | 
         
            -
                async send(button) {
         
     | 
| 82 | 
         
            -
                    console.log("Send");
         
     | 
| 83 | 
         
            -
                    let button_icon = button.find("i");
         
     | 
| 84 | 
         
            -
                    button.attr("status", "stop").attr("title", "Stop");
         
     | 
| 85 | 
         
            -
                    button_icon.removeClass().addClass("fa fa-circle-pause fa-fade-fast");
         
     | 
| 86 | 
         
            -
                    await this.post_user_input();
         
     | 
| 87 | 
         
            -
                    await this.stop(button);
         
     | 
| 88 | 
         
            -
                }
         
     | 
| 89 | 
         
             
                async stop(button) {
         
     | 
| 90 | 
         
            -
                    console.log("Stop");
         
     | 
| 91 | 
         
             
                    let button_icon = button.find("i");
         
     | 
| 92 | 
         
            -
                    this.requester.stop();
         
     | 
| 93 | 
         
             
                    stop_latest_message_animation();
         
     | 
| 94 | 
         
             
                    button.attr("status", "send").attr("title", "Send");
         
     | 
| 95 | 
         
             
                    button_icon
         
     | 
| 
         @@ -103,7 +104,7 @@ class SendUserInputButtonBinder { 
     | 
|
| 103 | 
         
             
            }
         
     | 
| 104 | 
         | 
| 105 | 
         
             
            class NewChatButtonBinder {
         
     | 
| 106 | 
         
            -
                constructor() { 
     | 
| 107 | 
         
             
                bind() {
         
     | 
| 108 | 
         
             
                    const button = $("#new-chat-session");
         
     | 
| 109 | 
         
             
                    button.attr("status", "new").attr("title", "New Chat");
         
     | 
| 
         @@ -114,7 +115,7 @@ class NewChatButtonBinder { 
     | 
|
| 114 | 
         
             
            }
         
     | 
| 115 | 
         | 
| 116 | 
         
             
            class OpenaiEndpointButtonBinder {
         
     | 
| 117 | 
         
            -
                constructor() { 
     | 
| 118 | 
         
             
                bind() {
         
     | 
| 119 | 
         
             
                    const button = $("#openai-endpoint-button");
         
     | 
| 120 | 
         
             
                    button.attr("title", "Submit Endpoint");
         
     | 
| 
         @@ -136,7 +137,7 @@ class OpenaiEndpointButtonBinder { 
     | 
|
| 136 | 
         
             
            }
         
     | 
| 137 | 
         | 
| 138 | 
         
             
            class OpenaiAPIKeyButtonBinder {
         
     | 
| 139 | 
         
            -
                constructor() { 
     | 
| 140 | 
         
             
                bind() {
         
     | 
| 141 | 
         
             
                    const button = $("#openai-api-key-button");
         
     | 
| 142 | 
         
             
                    button.attr("title", "Submit API Key");
         
     | 
| 
         @@ -153,7 +154,7 @@ class OpenaiAPIKeyButtonBinder { 
     | 
|
| 153 | 
         
             
            }
         
     | 
| 154 | 
         | 
| 155 | 
         
             
            class ShowEndpointAndKeyButtonBinder {
         
     | 
| 156 | 
         
            -
                constructor() { 
     | 
| 157 | 
         
             
                bind() {
         
     | 
| 158 | 
         
             
                    const button = $("#show-endpoint-and-key-button");
         
     | 
| 159 | 
         
             
                    button.attr("title", "Show endpoint and api key");
         
     | 
| 
         @@ -178,7 +179,7 @@ class ShowEndpointAndKeyButtonBinder { 
     | 
|
| 178 | 
         
             
            }
         
     | 
| 179 | 
         | 
| 180 | 
         
             
            class ScrollToBottomButtonBinder {
         
     | 
| 181 | 
         
            -
                constructor() { 
     | 
| 182 | 
         
             
                bind() {
         
     | 
| 183 | 
         
             
                    const button = $("#scroll-to-bottom-button");
         
     | 
| 184 | 
         
             
                    button.attr("title", "Scroll to bottom");
         
     | 
| 
         @@ -190,7 +191,7 @@ class ScrollToBottomButtonBinder { 
     | 
|
| 190 | 
         
             
            }
         
     | 
| 191 | 
         | 
| 192 | 
         
             
            class ScreenshotButtonBinder {
         
     | 
| 193 | 
         
            -
                constructor() { 
     | 
| 194 | 
         
             
                bind() {
         
     | 
| 195 | 
         
             
                    const button = $("#screenshot-button");
         
     | 
| 196 | 
         
             
                    button.attr("title", "Take screenshot for whole chat");
         
     | 
| 
         @@ -225,7 +226,7 @@ class ScreenshotButtonBinder { 
     | 
|
| 225 | 
         
             
            }
         
     | 
| 226 | 
         | 
| 227 | 
         
             
            class AvailableModelsSelectBinder {
         
     | 
| 228 | 
         
            -
                constructor() { 
     | 
| 229 | 
         
             
                bind() {
         
     | 
| 230 | 
         
             
                    const select = $("#available-models-select");
         
     | 
| 231 | 
         
             
                    select.change(() => {
         
     | 
| 
         | 
|
| 10 | 
         
             
            import { screen_scroller } from "../storage/states.js";
         
     | 
| 11 | 
         | 
| 12 | 
         
             
            export class ButtonsBinder {
         
     | 
| 13 | 
         
            +
                constructor() {}
         
     | 
| 14 | 
         
             
                bind() {
         
     | 
| 15 | 
         
             
                    let send_user_input_binder = new SendUserInputButtonBinder();
         
     | 
| 16 | 
         
             
                    send_user_input_binder.bind();
         
     | 
| 
         | 
|
| 69 | 
         
             
                    }
         
     | 
| 70 | 
         
             
                }
         
     | 
| 71 | 
         | 
| 72 | 
         
            +
                async send(button) {
         
     | 
| 73 | 
         
            +
                    // console.log("Send");
         
     | 
| 74 | 
         
            +
                    let button_icon = button.find("i");
         
     | 
| 75 | 
         
            +
                    button.attr("status", "stop").attr("title", "Stop");
         
     | 
| 76 | 
         
            +
                    button_icon.removeClass().addClass("fa fa-circle-pause fa-fade-fast");
         
     | 
| 77 | 
         
            +
                    await this.post_user_input();
         
     | 
| 78 | 
         
            +
                    await this.stop(button);
         
     | 
| 79 | 
         
            +
                }
         
     | 
| 80 | 
         
            +
             
     | 
| 81 | 
         
             
                async post_user_input() {
         
     | 
| 82 | 
         
             
                    let user_input_content = $("#user-input").val();
         
     | 
| 83 | 
         
             
                    console.log(user_input_content);
         
     | 
| 
         | 
|
| 85 | 
         
             
                    this.requester.create_messager_components();
         
     | 
| 86 | 
         
             
                    start_latest_message_animation();
         
     | 
| 87 | 
         
             
                    await this.requester.post();
         
     | 
| 88 | 
         
            +
                    this.requester.stop();
         
     | 
| 89 | 
         
             
                }
         
     | 
| 90 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 91 | 
         
             
                async stop(button) {
         
     | 
| 92 | 
         
            +
                    // console.log("Stop");
         
     | 
| 93 | 
         
             
                    let button_icon = button.find("i");
         
     | 
| 
         | 
|
| 94 | 
         
             
                    stop_latest_message_animation();
         
     | 
| 95 | 
         
             
                    button.attr("status", "send").attr("title", "Send");
         
     | 
| 96 | 
         
             
                    button_icon
         
     | 
| 
         | 
|
| 104 | 
         
             
            }
         
     | 
| 105 | 
         | 
| 106 | 
         
             
            class NewChatButtonBinder {
         
     | 
| 107 | 
         
            +
                constructor() {}
         
     | 
| 108 | 
         
             
                bind() {
         
     | 
| 109 | 
         
             
                    const button = $("#new-chat-session");
         
     | 
| 110 | 
         
             
                    button.attr("status", "new").attr("title", "New Chat");
         
     | 
| 
         | 
|
| 115 | 
         
             
            }
         
     | 
| 116 | 
         | 
| 117 | 
         
             
            class OpenaiEndpointButtonBinder {
         
     | 
| 118 | 
         
            +
                constructor() {}
         
     | 
| 119 | 
         
             
                bind() {
         
     | 
| 120 | 
         
             
                    const button = $("#openai-endpoint-button");
         
     | 
| 121 | 
         
             
                    button.attr("title", "Submit Endpoint");
         
     | 
| 
         | 
|
| 137 | 
         
             
            }
         
     | 
| 138 | 
         | 
| 139 | 
         
             
            class OpenaiAPIKeyButtonBinder {
         
     | 
| 140 | 
         
            +
                constructor() {}
         
     | 
| 141 | 
         
             
                bind() {
         
     | 
| 142 | 
         
             
                    const button = $("#openai-api-key-button");
         
     | 
| 143 | 
         
             
                    button.attr("title", "Submit API Key");
         
     | 
| 
         | 
|
| 154 | 
         
             
            }
         
     | 
| 155 | 
         | 
| 156 | 
         
             
            class ShowEndpointAndKeyButtonBinder {
         
     | 
| 157 | 
         
            +
                constructor() {}
         
     | 
| 158 | 
         
             
                bind() {
         
     | 
| 159 | 
         
             
                    const button = $("#show-endpoint-and-key-button");
         
     | 
| 160 | 
         
             
                    button.attr("title", "Show endpoint and api key");
         
     | 
| 
         | 
|
| 179 | 
         
             
            }
         
     | 
| 180 | 
         | 
| 181 | 
         
             
            class ScrollToBottomButtonBinder {
         
     | 
| 182 | 
         
            +
                constructor() {}
         
     | 
| 183 | 
         
             
                bind() {
         
     | 
| 184 | 
         
             
                    const button = $("#scroll-to-bottom-button");
         
     | 
| 185 | 
         
             
                    button.attr("title", "Scroll to bottom");
         
     | 
| 
         | 
|
| 191 | 
         
             
            }
         
     | 
| 192 | 
         | 
| 193 | 
         
             
            class ScreenshotButtonBinder {
         
     | 
| 194 | 
         
            +
                constructor() {}
         
     | 
| 195 | 
         
             
                bind() {
         
     | 
| 196 | 
         
             
                    const button = $("#screenshot-button");
         
     | 
| 197 | 
         
             
                    button.attr("title", "Take screenshot for whole chat");
         
     | 
| 
         | 
|
| 226 | 
         
             
            }
         
     | 
| 227 | 
         | 
| 228 | 
         
             
            class AvailableModelsSelectBinder {
         
     | 
| 229 | 
         
            +
                constructor() {}
         
     | 
| 230 | 
         
             
                bind() {
         
     | 
| 231 | 
         
             
                    const select = $("#available-models-select");
         
     | 
| 232 | 
         
             
                    select.change(() => {
         
     | 
    	
        components/chat_operator.js
    CHANGED
    
    | 
         @@ -102,7 +102,7 @@ export function update_message(json_chunks, content_displayer = null) { 
     | 
|
| 102 | 
         
             
                        console.log("role: " + role);
         
     | 
| 103 | 
         
             
                    }
         
     | 
| 104 | 
         
             
                    if (content) {
         
     | 
| 105 | 
         
            -
                        console.log(content);
         
     | 
| 106 | 
         
             
                        content_displayer.data(
         
     | 
| 107 | 
         
             
                            "raw_content",
         
     | 
| 108 | 
         
             
                            content_displayer.data("raw_content") + content
         
     | 
| 
         @@ -122,7 +122,7 @@ export function update_message(json_chunks, content_displayer = null) { 
     | 
|
| 122 | 
         
             
                    if (finish_reason === "stop") {
         
     | 
| 123 | 
         
             
                        console.log("[STOP]");
         
     | 
| 124 | 
         
             
                    }
         
     | 
| 125 | 
         
            -
                    console.log(item);
         
     | 
| 126 | 
         
             
                });
         
     | 
| 127 | 
         
             
                return json_chunks;
         
     | 
| 128 | 
         
             
            }
         
     | 
| 
         | 
|
| 102 | 
         
             
                        console.log("role: " + role);
         
     | 
| 103 | 
         
             
                    }
         
     | 
| 104 | 
         
             
                    if (content) {
         
     | 
| 105 | 
         
            +
                        // console.log(content);
         
     | 
| 106 | 
         
             
                        content_displayer.data(
         
     | 
| 107 | 
         
             
                            "raw_content",
         
     | 
| 108 | 
         
             
                            content_displayer.data("raw_content") + content
         
     | 
| 
         | 
|
| 122 | 
         
             
                    if (finish_reason === "stop") {
         
     | 
| 123 | 
         
             
                        console.log("[STOP]");
         
     | 
| 124 | 
         
             
                    }
         
     | 
| 125 | 
         
            +
                    // console.log(item);
         
     | 
| 126 | 
         
             
                });
         
     | 
| 127 | 
         
             
                return json_chunks;
         
     | 
| 128 | 
         
             
            }
         
     |