:gem: [Feature] Enable fill-in available models from multiple endpoints
Browse files- components/buttons_binder.js +1 -2
- components/llm_models_loader.js +0 -29
- networks/endpoint_storage.js +44 -0
- networks/llm_requester.js +2 -3
components/buttons_binder.js
CHANGED
@@ -7,7 +7,6 @@ import {
|
|
7 |
get_selected_llm_model,
|
8 |
create_messager,
|
9 |
} from "./chat_operator.js";
|
10 |
-
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";
|
@@ -248,7 +247,7 @@ class AvailableModelsSelectBinder {
|
|
248 |
const select = $("#available-models-select");
|
249 |
select.change(() => {
|
250 |
console.log(select.val());
|
251 |
-
|
252 |
});
|
253 |
}
|
254 |
}
|
|
|
7 |
get_selected_llm_model,
|
8 |
create_messager,
|
9 |
} from "./chat_operator.js";
|
|
|
10 |
|
11 |
import { screen_scroller } from "./screen_scroller.js";
|
12 |
import { chat_history_storer } from "../networks/chat_history_storer.js";
|
|
|
247 |
const select = $("#available-models-select");
|
248 |
select.change(() => {
|
249 |
console.log(select.val());
|
250 |
+
endpoint_storage.db.default_model = select.val();
|
251 |
});
|
252 |
}
|
253 |
}
|
components/llm_models_loader.js
CHANGED
@@ -1,32 +1,3 @@
|
|
1 |
-
import {
|
2 |
-
available_models,
|
3 |
-
AvailableModelsRequester,
|
4 |
-
} from "../networks/llm_requester.js";
|
5 |
-
|
6 |
-
export async function setup_available_models_on_select(default_option = null) {
|
7 |
-
var select = $("#available-models-select");
|
8 |
-
select.empty();
|
9 |
-
let available_models_requester = new AvailableModelsRequester();
|
10 |
-
await available_models_requester.get();
|
11 |
-
available_models.forEach((value, index) => {
|
12 |
-
const option = new Option(value, value);
|
13 |
-
select.append(option);
|
14 |
-
});
|
15 |
-
let default_model = "";
|
16 |
-
let local_default_model = localStorage.getItem("default_model");
|
17 |
-
if (local_default_model && available_models.includes(local_default_model)) {
|
18 |
-
default_model = local_default_model;
|
19 |
-
} else if (available_models) {
|
20 |
-
default_model = available_models[0];
|
21 |
-
localStorage.setItem("default_model", default_model);
|
22 |
-
} else {
|
23 |
-
default_model = "";
|
24 |
-
}
|
25 |
-
|
26 |
-
select.val(default_model);
|
27 |
-
console.log(`default_model: ${select.val()}`);
|
28 |
-
}
|
29 |
-
|
30 |
export async function setup_temperature_on_select(default_option = null) {
|
31 |
var select = $("#temperature-select");
|
32 |
select.empty();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
export async function setup_temperature_on_select(default_option = null) {
|
2 |
var select = $("#temperature-select");
|
3 |
select.empty();
|
networks/endpoint_storage.js
CHANGED
@@ -1,9 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
class EndpointStorageItem {}
|
2 |
|
3 |
class EndpointStorage {
|
4 |
constructor() {
|
5 |
this.init_database();
|
6 |
this.render_endpoint_and_api_key_items();
|
|
|
7 |
}
|
8 |
init_database() {
|
9 |
this.db = new Dexie("endpoints");
|
@@ -99,6 +105,44 @@ class EndpointStorage {
|
|
99 |
}
|
100 |
});
|
101 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
render_endpoint_and_api_key_items() {
|
103 |
this.create_endpoint_and_api_key_items();
|
104 |
this.bind_endpoint_and_api_key_buttons();
|
|
|
1 |
+
import {
|
2 |
+
available_models,
|
3 |
+
AvailableModelsRequester,
|
4 |
+
} from "../networks/llm_requester.js";
|
5 |
+
|
6 |
class EndpointStorageItem {}
|
7 |
|
8 |
class EndpointStorage {
|
9 |
constructor() {
|
10 |
this.init_database();
|
11 |
this.render_endpoint_and_api_key_items();
|
12 |
+
this.fill_available_models_select();
|
13 |
}
|
14 |
init_database() {
|
15 |
this.db = new Dexie("endpoints");
|
|
|
105 |
}
|
106 |
});
|
107 |
}
|
108 |
+
fill_available_models_select() {
|
109 |
+
var select = $("#available-models-select");
|
110 |
+
select.empty();
|
111 |
+
|
112 |
+
// for loop the endpoints in endpoint_storage.db.endpoints
|
113 |
+
this.db.endpoints.toArray().then(async (entries) => {
|
114 |
+
for (const entry of entries) {
|
115 |
+
let endpoint = entry.endpoint;
|
116 |
+
console.log("fetch available models for endpoint:", endpoint);
|
117 |
+
let available_models_requester = new AvailableModelsRequester(
|
118 |
+
endpoint
|
119 |
+
);
|
120 |
+
await available_models_requester.get();
|
121 |
+
}
|
122 |
+
available_models.forEach((value, index) => {
|
123 |
+
const option = new Option(value, value);
|
124 |
+
select.append(option);
|
125 |
+
});
|
126 |
+
});
|
127 |
+
|
128 |
+
// set default model
|
129 |
+
let default_model = "";
|
130 |
+
let local_default_model = endpoint_storage.db.default_model;
|
131 |
+
if (
|
132 |
+
local_default_model &&
|
133 |
+
available_models.includes(local_default_model)
|
134 |
+
) {
|
135 |
+
default_model = local_default_model;
|
136 |
+
} else if (available_models) {
|
137 |
+
default_model = available_models[0];
|
138 |
+
endpoint_storage.db.default_model = default_model;
|
139 |
+
} else {
|
140 |
+
default_model = "";
|
141 |
+
}
|
142 |
+
|
143 |
+
select.val(default_model);
|
144 |
+
console.log(`default_model: ${select.val()}`);
|
145 |
+
}
|
146 |
render_endpoint_and_api_key_items() {
|
147 |
this.create_endpoint_and_api_key_items();
|
148 |
this.bind_endpoint_and_api_key_buttons();
|
networks/llm_requester.js
CHANGED
@@ -100,9 +100,8 @@ export class ChatCompletionsRequester {
|
|
100 |
|
101 |
export var available_models = ["notes"];
|
102 |
export class AvailableModelsRequester {
|
103 |
-
constructor(openai_endpoint
|
104 |
-
this.openai_endpoint =
|
105 |
-
openai_endpoint || localStorage.getItem("openai_endpoint");
|
106 |
this.backend_request_endpoint = "/models";
|
107 |
this.controller = new AbortController();
|
108 |
}
|
|
|
100 |
|
101 |
export var available_models = ["notes"];
|
102 |
export class AvailableModelsRequester {
|
103 |
+
constructor(openai_endpoint) {
|
104 |
+
this.openai_endpoint = openai_endpoint;
|
|
|
105 |
this.backend_request_endpoint = "/models";
|
106 |
this.controller = new AbortController();
|
107 |
}
|