Hansimov commited on
Commit
d2955e2
1 Parent(s): f3794ea

:recycle: [Refactor] Separate construct_model_name_and_value from fill_available_models_select

Browse files
Files changed (1) hide show
  1. storages/endpoint_storage.js +16 -15
storages/endpoint_storage.js CHANGED
@@ -182,20 +182,14 @@ class EndpointStorage {
182
  return this.fetch_available_models(row.endpoint).then(
183
  (available_models) => {
184
  available_models.forEach((model_id) => {
185
- // if model duplicated in available_models_select values,
186
- // then attach endpoint host name
187
- let model_name = model_id;
188
- let endpoint_hostname = new URL(
189
- row.endpoint
190
- ).hostname
191
- .split(".")[0]
192
- .split("-")[0];
193
- let model_id_with_endpoint = `${row.endpoint}|${model_id}`;
194
-
195
- model_name = `${model_id} (${endpoint_hostname})`;
196
- const option = new Option(
197
- model_name,
198
- model_id_with_endpoint
199
  );
200
  available_models_select.append(option);
201
  });
@@ -207,7 +201,14 @@ class EndpointStorage {
207
  });
208
  });
209
  }
210
-
 
 
 
 
 
 
 
211
  set_default_model() {
212
  let storage_default_model = localStorage.getItem("default_model");
213
  // format of storage_default_model is `{endpoint}|{model_id}`
 
182
  return this.fetch_available_models(row.endpoint).then(
183
  (available_models) => {
184
  available_models.forEach((model_id) => {
185
+ let model_name_and_value =
186
+ this.construct_model_name_and_value(
187
+ row.endpoint,
188
+ model_id
189
+ );
190
+ let option = new Option(
191
+ model_name_and_value[0],
192
+ model_name_and_value[1]
 
 
 
 
 
 
193
  );
194
  available_models_select.append(option);
195
  });
 
201
  });
202
  });
203
  }
204
+ construct_model_name_and_value(endpoint, model_id) {
205
+ let endpoint_hostname = new URL(endpoint).hostname
206
+ .split(".")[0]
207
+ .split("-")[0];
208
+ let model_name = `${model_id} (${endpoint_hostname})`;
209
+ let model_value = `${endpoint}|${model_id}`;
210
+ return [model_name, model_value];
211
+ }
212
  set_default_model() {
213
  let storage_default_model = localStorage.getItem("default_model");
214
  // format of storage_default_model is `{endpoint}|{model_id}`