:recycle: [Refactor] Separate construct_model_name_and_value from fill_available_models_select
Browse files- 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 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 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}`
|