:gem: [Feature] New EndpointStorage: create items and bind buttons for endpoint and api key
Browse files
.github/workflows/sync_to_huggingface_space.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
name: Sync to Hugging Face hub
|
2 |
on:
|
3 |
-
push:
|
4 |
-
|
5 |
workflow_dispatch:
|
6 |
|
7 |
jobs:
|
|
|
1 |
name: Sync to Hugging Face hub
|
2 |
on:
|
3 |
+
# push:
|
4 |
+
# branches: [main]
|
5 |
workflow_dispatch:
|
6 |
|
7 |
jobs:
|
networks/endpoint_storage.js
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
10 |
+
this.db.version(1).stores({
|
11 |
+
endpoints: "index, endpoint, api_key",
|
12 |
+
default_model: "model",
|
13 |
+
});
|
14 |
+
this.db.endpoints.count((count) => {
|
15 |
+
console.log(`${count} endpoints loaded.`);
|
16 |
+
});
|
17 |
+
}
|
18 |
+
clear_database() {
|
19 |
+
this.db.endpoints.clear();
|
20 |
+
console.log("endpoints cleared.");
|
21 |
+
}
|
22 |
+
get_endpoint_and_api_key_item_html() {
|
23 |
+
let endpoint_and_api_key_item_html = `
|
24 |
+
<div class="row mt-2 no-gutters">
|
25 |
+
<div class="col-auto">
|
26 |
+
<button class="btn px-0 remove-endpoint-and-key-button">
|
27 |
+
<i class="fa fa-circle-minus"></i>
|
28 |
+
</button>
|
29 |
+
</div>
|
30 |
+
<div class="col pl-0">
|
31 |
+
<input class="form-control endpoint-input" rows="1"
|
32 |
+
placeholder="Input Endpoint URL"
|
33 |
+
></input>
|
34 |
+
</div>
|
35 |
+
<div class="col pl-0">
|
36 |
+
<input class="form-control api-key-input" rows="1"
|
37 |
+
placeholder="Input API Key, then click √"
|
38 |
+
></input>
|
39 |
+
</div>
|
40 |
+
<div class="col-auto px-0">
|
41 |
+
<button class="btn endpoint-submit-button">
|
42 |
+
<i class="fa fa-check"></i>
|
43 |
+
</button>
|
44 |
+
</div>
|
45 |
+
</div>
|
46 |
+
`;
|
47 |
+
return endpoint_and_api_key_item_html;
|
48 |
+
}
|
49 |
+
add_endpoint_and_api_key_item() {
|
50 |
+
let endpoint_and_api_key_items = $("#endpoint-and-api-key-items");
|
51 |
+
endpoint_and_api_key_items.prepend(
|
52 |
+
this.get_endpoint_and_api_key_item_html()
|
53 |
+
);
|
54 |
+
this.bind_endpoint_and_api_key_buttons();
|
55 |
+
}
|
56 |
+
create_endpoint_and_api_key_items() {
|
57 |
+
let endpoint_and_api_key_items = $("#endpoint-and-api-key-items");
|
58 |
+
let endpoints = this.db.endpoints;
|
59 |
+
endpoint_and_api_key_items.empty();
|
60 |
+
|
61 |
+
endpoints.each((row) => {
|
62 |
+
let endpoint_and_api_key_item_html =
|
63 |
+
this.get_endpoint_and_api_key_item_html();
|
64 |
+
let endpoint_and_api_key_item = $(endpoint_and_api_key_item_html);
|
65 |
+
let endpoint_input =
|
66 |
+
endpoint_and_api_key_item.find(".endpoint-input");
|
67 |
+
endpoint_input.val(row.endpoint);
|
68 |
+
let api_key_input =
|
69 |
+
endpoint_and_api_key_item.find(".api-key-input");
|
70 |
+
api_key_input.val(row.api_key);
|
71 |
+
endpoint_and_api_key_items.prepend(endpoint_and_api_key_item);
|
72 |
+
});
|
73 |
+
}
|
74 |
+
bind_endpoint_and_api_key_buttons() {
|
75 |
+
let endpoint_submit_buttons = $(".endpoint-submit-button");
|
76 |
+
let self = this;
|
77 |
+
endpoint_submit_buttons.click(function () {
|
78 |
+
let endpoint_input = $(this)
|
79 |
+
.parent()
|
80 |
+
.parent()
|
81 |
+
.find(".endpoint-input");
|
82 |
+
let endpoint_input_value = endpoint_input.val().trim();
|
83 |
+
let api_key_input = $(this)
|
84 |
+
.parent()
|
85 |
+
.parent()
|
86 |
+
.find(".api-key-input");
|
87 |
+
let api_key_input_value = api_key_input.val().trim();
|
88 |
+
|
89 |
+
if (endpoint_input_value === "") {
|
90 |
+
console.log("Endpoint is empty.");
|
91 |
+
return;
|
92 |
+
} else {
|
93 |
+
self.db.endpoints.put({
|
94 |
+
index: endpoint_input_value,
|
95 |
+
endpoint: endpoint_input_value,
|
96 |
+
api_key: api_key_input_value,
|
97 |
+
});
|
98 |
+
console.log(`new_endpoint: ${endpoint_input_value}`);
|
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();
|
105 |
+
}
|
106 |
+
}
|
107 |
+
|
108 |
+
export let endpoint_storage = new EndpointStorage();
|