:gem: [Feature] New Buttons Binder: Add and toggle endpoint and api key items
Browse files- components/buttons_binder.js +26 -67
- index.html +7 -20
components/buttons_binder.js
CHANGED
@@ -11,20 +11,21 @@ import { setup_available_models_on_select } from "./llm_models_loader.js";
|
|
11 |
|
12 |
import { screen_scroller } from "./screen_scroller.js";
|
13 |
import { chat_history_storer } from "../networks/chat_history_storer.js";
|
|
|
14 |
|
15 |
export class ButtonsBinder {
|
16 |
-
constructor() {
|
17 |
bind() {
|
18 |
let send_user_input_binder = new SendUserInputButtonBinder();
|
19 |
send_user_input_binder.bind();
|
20 |
let new_chat_binder = new NewChatButtonBinder();
|
21 |
new_chat_binder.bind();
|
22 |
-
let
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
let scroll_to_bottom_binder = new ScrollToBottomButtonBinder();
|
29 |
scroll_to_bottom_binder.bind();
|
30 |
let screenshot_button_binder = new ScreenshotButtonBinder();
|
@@ -117,7 +118,7 @@ class SendUserInputButtonBinder {
|
|
117 |
}
|
118 |
|
119 |
class NewChatButtonBinder {
|
120 |
-
constructor() {
|
121 |
bind() {
|
122 |
const button = $("#new-chat-session");
|
123 |
button.attr("status", "new").attr("title", "New Chat");
|
@@ -128,72 +129,29 @@ class NewChatButtonBinder {
|
|
128 |
}
|
129 |
}
|
130 |
|
131 |
-
class
|
132 |
-
constructor() {
|
133 |
bind() {
|
134 |
-
const button = $("#
|
135 |
-
button.attr("title", "
|
136 |
-
const stored_openai_endpoint = localStorage.getItem("openai_endpoint");
|
137 |
-
if (stored_openai_endpoint) {
|
138 |
-
$("#openai-endpoint").val(stored_openai_endpoint);
|
139 |
-
setup_available_models_on_select();
|
140 |
-
console.log(`openai_endpoint: ${stored_openai_endpoint}`);
|
141 |
-
}
|
142 |
-
button.click(() => {
|
143 |
-
console.log($("#openai-endpoint").val());
|
144 |
-
localStorage.setItem(
|
145 |
-
"openai_endpoint",
|
146 |
-
$("#openai-endpoint").val()
|
147 |
-
);
|
148 |
-
setup_available_models_on_select();
|
149 |
-
});
|
150 |
-
}
|
151 |
-
}
|
152 |
-
|
153 |
-
class OpenaiAPIKeyButtonBinder {
|
154 |
-
constructor() { }
|
155 |
-
bind() {
|
156 |
-
const button = $("#openai-api-key-button");
|
157 |
-
button.attr("title", "Submit API Key");
|
158 |
-
const stored_openai_api_key = localStorage.getItem("openai_api_key");
|
159 |
-
if (stored_openai_api_key) {
|
160 |
-
$("#openai-api-key").val(stored_openai_api_key);
|
161 |
-
console.log(`openai_api_key: ${stored_openai_api_key}`);
|
162 |
-
}
|
163 |
button.click(() => {
|
164 |
-
|
165 |
-
localStorage.setItem("openai_api_key", $("#openai-api-key").val());
|
166 |
});
|
167 |
}
|
168 |
}
|
169 |
-
|
170 |
-
|
171 |
-
constructor() { }
|
172 |
bind() {
|
173 |
-
const button = $("#
|
174 |
-
button.attr("title", "
|
175 |
-
|
176 |
-
if (localStorage.getItem("openai_endpoint")) {
|
177 |
-
$("#openai-endpoint").parent().hide();
|
178 |
-
$("#openai-endpoint-button").parent().hide();
|
179 |
-
}
|
180 |
-
|
181 |
-
if (localStorage.getItem("openai_api_key")) {
|
182 |
-
$("#openai-api-key").parent().hide();
|
183 |
-
$("#openai-api-key-button").parent().hide();
|
184 |
-
}
|
185 |
-
|
186 |
button.click(() => {
|
187 |
-
|
188 |
-
$("#openai-endpoint-button").parent().toggle();
|
189 |
-
$("#openai-api-key").parent().toggle();
|
190 |
-
$("#openai-api-key-button").parent().toggle();
|
191 |
});
|
192 |
}
|
193 |
}
|
194 |
|
195 |
class ScrollToBottomButtonBinder {
|
196 |
-
constructor() {
|
197 |
bind() {
|
198 |
const button = $("#scroll-to-bottom-button");
|
199 |
button.attr("title", "Scroll to bottom");
|
@@ -205,7 +163,7 @@ class ScrollToBottomButtonBinder {
|
|
205 |
}
|
206 |
|
207 |
class ScreenshotButtonBinder {
|
208 |
-
constructor() {
|
209 |
bind() {
|
210 |
const button = $("#screenshot-button");
|
211 |
button.attr("title", "Take screenshot for whole chat");
|
@@ -240,7 +198,7 @@ class ScreenshotButtonBinder {
|
|
240 |
}
|
241 |
|
242 |
class ChatHistorySidebarToggleButtonBinder {
|
243 |
-
constructor() {
|
244 |
get_show_sidebar_storage() {
|
245 |
return localStorage.getItem("show_chat_history_sidebar");
|
246 |
}
|
@@ -260,7 +218,8 @@ class ChatHistorySidebarToggleButtonBinder {
|
|
260 |
toggle_button.click(() => {
|
261 |
sidebar.toggleClass("show");
|
262 |
localStorage.setItem(
|
263 |
-
"show_chat_history_sidebar",
|
|
|
264 |
);
|
265 |
});
|
266 |
|
@@ -273,7 +232,7 @@ class ChatHistorySidebarToggleButtonBinder {
|
|
273 |
}
|
274 |
|
275 |
class ClearChatHistoryButtonBinder {
|
276 |
-
constructor() {
|
277 |
bind() {
|
278 |
const button = $("#clear-chat-history-button");
|
279 |
button.attr("title", "Clear chat history");
|
@@ -284,7 +243,7 @@ class ClearChatHistoryButtonBinder {
|
|
284 |
}
|
285 |
|
286 |
class AvailableModelsSelectBinder {
|
287 |
-
constructor() {
|
288 |
bind() {
|
289 |
const select = $("#available-models-select");
|
290 |
select.change(() => {
|
|
|
11 |
|
12 |
import { screen_scroller } from "./screen_scroller.js";
|
13 |
import { chat_history_storer } from "../networks/chat_history_storer.js";
|
14 |
+
import { endpoint_storage } from "../networks/endpoint_storage.js";
|
15 |
|
16 |
export class ButtonsBinder {
|
17 |
+
constructor() {}
|
18 |
bind() {
|
19 |
let send_user_input_binder = new SendUserInputButtonBinder();
|
20 |
send_user_input_binder.bind();
|
21 |
let new_chat_binder = new NewChatButtonBinder();
|
22 |
new_chat_binder.bind();
|
23 |
+
let toggle_endpoint_and_api_key_items_button_binder =
|
24 |
+
new ToggleEndpointAndApiKeyItemsButtonBinder();
|
25 |
+
toggle_endpoint_and_api_key_items_button_binder.bind();
|
26 |
+
let add_endpoint_and_api_key_item_button_binder =
|
27 |
+
new AddEndpointAndApiKeyItemButtonBinder();
|
28 |
+
add_endpoint_and_api_key_item_button_binder.bind();
|
29 |
let scroll_to_bottom_binder = new ScrollToBottomButtonBinder();
|
30 |
scroll_to_bottom_binder.bind();
|
31 |
let screenshot_button_binder = new ScreenshotButtonBinder();
|
|
|
118 |
}
|
119 |
|
120 |
class NewChatButtonBinder {
|
121 |
+
constructor() {}
|
122 |
bind() {
|
123 |
const button = $("#new-chat-session");
|
124 |
button.attr("status", "new").attr("title", "New Chat");
|
|
|
129 |
}
|
130 |
}
|
131 |
|
132 |
+
class ToggleEndpointAndApiKeyItemsButtonBinder {
|
133 |
+
constructor() {}
|
134 |
bind() {
|
135 |
+
const button = $("#toggle-endpoint-and-api-key-items-button");
|
136 |
+
button.attr("title", "Toggle endpoint and api key items");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
button.click(() => {
|
138 |
+
$("#endpoint-and-api-key-items").toggle();
|
|
|
139 |
});
|
140 |
}
|
141 |
}
|
142 |
+
class AddEndpointAndApiKeyItemButtonBinder {
|
143 |
+
constructor() {}
|
|
|
144 |
bind() {
|
145 |
+
const button = $("#add-endpoint-and-api-key-item-button");
|
146 |
+
button.attr("title", "Add endpoint and api key item");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
button.click(() => {
|
148 |
+
endpoint_storage.add_endpoint_and_api_key_item();
|
|
|
|
|
|
|
149 |
});
|
150 |
}
|
151 |
}
|
152 |
|
153 |
class ScrollToBottomButtonBinder {
|
154 |
+
constructor() {}
|
155 |
bind() {
|
156 |
const button = $("#scroll-to-bottom-button");
|
157 |
button.attr("title", "Scroll to bottom");
|
|
|
163 |
}
|
164 |
|
165 |
class ScreenshotButtonBinder {
|
166 |
+
constructor() {}
|
167 |
bind() {
|
168 |
const button = $("#screenshot-button");
|
169 |
button.attr("title", "Take screenshot for whole chat");
|
|
|
198 |
}
|
199 |
|
200 |
class ChatHistorySidebarToggleButtonBinder {
|
201 |
+
constructor() {}
|
202 |
get_show_sidebar_storage() {
|
203 |
return localStorage.getItem("show_chat_history_sidebar");
|
204 |
}
|
|
|
218 |
toggle_button.click(() => {
|
219 |
sidebar.toggleClass("show");
|
220 |
localStorage.setItem(
|
221 |
+
"show_chat_history_sidebar",
|
222 |
+
sidebar.hasClass("show").toString()
|
223 |
);
|
224 |
});
|
225 |
|
|
|
232 |
}
|
233 |
|
234 |
class ClearChatHistoryButtonBinder {
|
235 |
+
constructor() {}
|
236 |
bind() {
|
237 |
const button = $("#clear-chat-history-button");
|
238 |
button.attr("title", "Clear chat history");
|
|
|
243 |
}
|
244 |
|
245 |
class AvailableModelsSelectBinder {
|
246 |
+
constructor() {}
|
247 |
bind() {
|
248 |
const select = $("#available-models-select");
|
249 |
select.change(() => {
|
index.html
CHANGED
@@ -47,32 +47,19 @@
|
|
47 |
<div id="messagers-container" class="container my-3 py-1"></div>
|
48 |
</div>
|
49 |
<div id="user-interactions" class="container fixed-bottom mb-3">
|
50 |
-
<div
|
51 |
-
<div class="col px-0">
|
52 |
-
<input id="openai-endpoint" class="form-control" rows="1"
|
53 |
-
placeholder="Input Endpoint URL, then click √"></input>
|
54 |
-
</div>
|
55 |
-
<div class="col-auto px-0">
|
56 |
-
<button id="openai-endpoint-button" class="btn">
|
57 |
-
<i class="fa fa-check"></i>
|
58 |
-
</button>
|
59 |
-
</div>
|
60 |
-
<div class="col px-0">
|
61 |
-
<input id="openai-api-key" class="form-control" rows="1"
|
62 |
-
placeholder="Input API Key, then click √"></input>
|
63 |
-
</div>
|
64 |
-
<div class="col-auto px-0">
|
65 |
-
<button id="openai-api-key-button" class="btn">
|
66 |
-
<i class="fa fa-check"></i>
|
67 |
-
</button>
|
68 |
-
</div>
|
69 |
</div>
|
70 |
<div class="mt-2 row no-gutters">
|
71 |
<div class="col-auto">
|
72 |
-
<button id="
|
73 |
<i class="fa fa-key"></i>
|
74 |
</button>
|
75 |
</div>
|
|
|
|
|
|
|
|
|
|
|
76 |
<div class="col px-0">
|
77 |
<select class="form-select" id="available-models-select" title="Available Models"></select>
|
78 |
</div>
|
|
|
47 |
<div id="messagers-container" class="container my-3 py-1"></div>
|
48 |
</div>
|
49 |
<div id="user-interactions" class="container fixed-bottom mb-3">
|
50 |
+
<div id="endpoint-and-api-key-items">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
</div>
|
52 |
<div class="mt-2 row no-gutters">
|
53 |
<div class="col-auto">
|
54 |
+
<button id="toggle-endpoint-and-api-key-items-button" class="btn px-0">
|
55 |
<i class="fa fa-key"></i>
|
56 |
</button>
|
57 |
</div>
|
58 |
+
<div class="col-auto">
|
59 |
+
<button id="add-endpoint-and-api-key-item-button" class="btn px-0 ">
|
60 |
+
<i class="fa fa-circle-plus"></i>
|
61 |
+
</button>
|
62 |
+
</div>
|
63 |
<div class="col px-0">
|
64 |
<select class="form-select" id="available-models-select" title="Available Models"></select>
|
65 |
</div>
|