Hansimov commited on
Commit
120437c
1 Parent(s): cf6dabc

:gem: [Feature] Set available models on select when loading or updating endpoint

Browse files
components/buttons_binder.js CHANGED
@@ -5,11 +5,12 @@ import {
5
  create_new_chat_session,
6
  get_latest_message_content_displayer,
7
  } from "./chat_operator.js";
 
8
 
9
  import { screen_scroller } from "../storage/states.js";
10
 
11
  export class ButtonsBinder {
12
- constructor() {}
13
  bind() {
14
  let send_user_input_binder = new SendUserInputButtonBinder();
15
  send_user_input_binder.bind();
@@ -102,7 +103,7 @@ class SendUserInputButtonBinder {
102
  }
103
 
104
  class NewChatButtonBinder {
105
- constructor() {}
106
  bind() {
107
  const button = $("#new-chat-session");
108
  button.attr("status", "new").attr("title", "New Chat");
@@ -113,13 +114,14 @@ class NewChatButtonBinder {
113
  }
114
 
115
  class OpenaiEndpointButtonBinder {
116
- constructor() {}
117
  bind() {
118
  const button = $("#openai-endpoint-button");
119
  button.attr("title", "Submit Endpoint");
120
  const stored_openai_endpoint = localStorage.getItem("openai_endpoint");
121
  if (stored_openai_endpoint) {
122
  $("#openai-endpoint").val(stored_openai_endpoint);
 
123
  console.log(`GET OpenAI Endpoint: ${stored_openai_endpoint}`);
124
  }
125
  button.click(() => {
@@ -128,12 +130,13 @@ class OpenaiEndpointButtonBinder {
128
  "openai_endpoint",
129
  $("#openai-endpoint").val()
130
  );
 
131
  });
132
  }
133
  }
134
 
135
  class OpenaiAPIKeyButtonBinder {
136
- constructor() {}
137
  bind() {
138
  const button = $("#openai-api-key-button");
139
  button.attr("title", "Submit API Key");
@@ -150,7 +153,7 @@ class OpenaiAPIKeyButtonBinder {
150
  }
151
 
152
  class ShowEndpointAndKeyButtonBinder {
153
- constructor() {}
154
  bind() {
155
  const button = $("#show-endpoint-and-key-button");
156
  button.attr("title", "Show endpoint and api key");
@@ -175,7 +178,7 @@ class ShowEndpointAndKeyButtonBinder {
175
  }
176
 
177
  class ScrollToBottomButtonBinder {
178
- constructor() {}
179
  bind() {
180
  const button = $("#scroll-to-bottom-button");
181
  button.attr("title", "Scroll to bottom");
@@ -187,7 +190,7 @@ class ScrollToBottomButtonBinder {
187
  }
188
 
189
  class ScreenshotButtonBinder {
190
- constructor() {}
191
  bind() {
192
  const button = $("#screenshot-button");
193
  button.attr("title", "Take screenshot for whole chat");
@@ -222,7 +225,7 @@ class ScreenshotButtonBinder {
222
  }
223
 
224
  class AvailableModelsSelectBinder {
225
- constructor() {}
226
  bind() {
227
  const select = $("#available-models-select");
228
  select.change(() => {
 
5
  create_new_chat_session,
6
  get_latest_message_content_displayer,
7
  } from "./chat_operator.js";
8
+ import { setup_available_models_on_select } from "./llm_models_loader.js";
9
 
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();
 
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
  }
115
 
116
  class OpenaiEndpointButtonBinder {
117
+ constructor() { }
118
  bind() {
119
  const button = $("#openai-endpoint-button");
120
  button.attr("title", "Submit Endpoint");
121
  const stored_openai_endpoint = localStorage.getItem("openai_endpoint");
122
  if (stored_openai_endpoint) {
123
  $("#openai-endpoint").val(stored_openai_endpoint);
124
+ setup_available_models_on_select();
125
  console.log(`GET OpenAI Endpoint: ${stored_openai_endpoint}`);
126
  }
127
  button.click(() => {
 
130
  "openai_endpoint",
131
  $("#openai-endpoint").val()
132
  );
133
+ setup_available_models_on_select();
134
  });
135
  }
136
  }
137
 
138
  class OpenaiAPIKeyButtonBinder {
139
+ constructor() { }
140
  bind() {
141
  const button = $("#openai-api-key-button");
142
  button.attr("title", "Submit API Key");
 
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
  }
179
 
180
  class ScrollToBottomButtonBinder {
181
+ constructor() { }
182
  bind() {
183
  const button = $("#scroll-to-bottom-button");
184
  button.attr("title", "Scroll to bottom");
 
190
  }
191
 
192
  class ScreenshotButtonBinder {
193
+ constructor() { }
194
  bind() {
195
  const button = $("#screenshot-button");
196
  button.attr("title", "Take screenshot for whole chat");
 
225
  }
226
 
227
  class AvailableModelsSelectBinder {
228
+ constructor() { }
229
  bind() {
230
  const select = $("#available-models-select");
231
  select.change(() => {
components/inputs_binder.js CHANGED
@@ -1,12 +1,8 @@
1
- import {
2
- setup_hardcoded_available_models_on_select,
3
- setup_temperature_on_select,
4
- } from "../components/llm_models_loader.js";
5
 
6
  export class InputsBinder {
7
- constructor() {}
8
  bind() {
9
- setup_hardcoded_available_models_on_select();
10
  setup_temperature_on_select();
11
  let user_input_resizer = new UserInputResizer();
12
  user_input_resizer.bind();
@@ -17,7 +13,7 @@ export class InputsBinder {
17
  }
18
 
19
  class UserInputResizer {
20
- constructor() {}
21
  bind() {
22
  // https://stackoverflow.com/questions/37629860/automatically-resizing-textarea-in-bootstrap
23
  document.getElementById("user-input").addEventListener(
@@ -32,7 +28,7 @@ class UserInputResizer {
32
  }
33
 
34
  class ChatSessionContainerResizeBinder {
35
- constructor() {}
36
  bind() {
37
  this.resize();
38
  $(window).on("resize", this.resize);
 
1
+ import { setup_temperature_on_select } from "../components/llm_models_loader.js";
 
 
 
2
 
3
  export class InputsBinder {
4
+ constructor() { }
5
  bind() {
 
6
  setup_temperature_on_select();
7
  let user_input_resizer = new UserInputResizer();
8
  user_input_resizer.bind();
 
13
  }
14
 
15
  class UserInputResizer {
16
+ constructor() { }
17
  bind() {
18
  // https://stackoverflow.com/questions/37629860/automatically-resizing-textarea-in-bootstrap
19
  document.getElementById("user-input").addEventListener(
 
28
  }
29
 
30
  class ChatSessionContainerResizeBinder {
31
+ constructor() { }
32
  bind() {
33
  this.resize();
34
  $(window).on("resize", this.resize);
components/llm_models_loader.js CHANGED
@@ -1,7 +1,4 @@
1
- import {
2
- request_available_models,
3
- available_models,
4
- } from "../networks/llm_requester.js";
5
 
6
  export async function setup_hardcoded_available_models_on_select(
7
  default_option = null
@@ -32,6 +29,32 @@ export async function setup_hardcoded_available_models_on_select(
32
  }
33
 
34
  export async function setup_available_models_on_select(default_option = null) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  var select = $("#available-models-select");
36
  select.empty();
37
  await request_available_models();
 
1
+ import { available_models, AvailableModelsRequester } from "../networks/llm_requester.js";
 
 
 
2
 
3
  export async function setup_hardcoded_available_models_on_select(
4
  default_option = null
 
29
  }
30
 
31
  export async function setup_available_models_on_select(default_option = null) {
32
+ var select = $("#available-models-select");
33
+ select.empty();
34
+ let available_models_requester = new AvailableModelsRequester();
35
+ await available_models_requester.get();
36
+ available_models.forEach((value, index) => {
37
+ const option = new Option(value, value);
38
+ select.append(option);
39
+ });
40
+ let default_model = "";
41
+ let local_default_model = localStorage.getItem("default_model");
42
+ if (
43
+ local_default_model && available_models.includes(local_default_model)
44
+ ) {
45
+ default_model = local_default_model;
46
+ } else if (available_models) {
47
+ default_model = available_models[0];
48
+ localStorage.setItem("default_model", default_model);
49
+ } else {
50
+ default_model = "";
51
+ }
52
+
53
+ select.val(default_model);
54
+ console.log(`Default model: ${select.val()}`);
55
+ }
56
+
57
+ export async function setup_working_available_models_on_select(default_option = null) {
58
  var select = $("#available-models-select");
59
  select.empty();
60
  await request_available_models();