-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
326 lines (297 loc) · 12.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Generate Config Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="module" src="component/Selector.js"></script>
<style>
.clickButton {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
outline: none;
text-decoration: none;
user-select: none;
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.25);
}
.clickButton:hover {
filter: contrast(1.02);
}
.clickButton:active {
filter: brightness(0.98);
transform: scale(0.99);
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.25);
}
.copy:hover {
filter: contrast(1.02);
}
.copy:active {
filter: brightness(0.98);
transform: scale(0.9);
}
</style>
</head>
<body>
<div style="font-size: 1.5rem;">Model:</div>
<div style="display: flex;margin-top: 0.4rem;" id="modelPlace">
<selector-component id="modelSelector" style="flex:1;"
placeholder="Choose a model to start a magical journey!"
mainColor="#000"></selector-component>
<div id="modelBlock" style="margin-left: 0.8rem;flex:1;display: none;">
<selector-component id="fileSelector" autoSelectFirst="true"
placeholder="Select model file" mainColor="#000"></selector-component>
</div>
</div>
<div style="display: flex;flex-direction: column;" id="promptPlace">
<div style="font-size: 1.5rem;margin-top: 1rem;">System prompt:</div>
<textarea disabled id="systemInput"
style="margin-top:0.4rem;line-height: 1.5rem;padding: 0.8rem 1rem;border-radius:0.6rem;border:1px solid black;"
placeholder="System prompt"></textarea>
<div style="font-size: 1.5rem;margin-top: 1rem;">Rag prompt:</div>
<textarea disabled id="ragInput"
style="margin-top:0.4rem;line-height: 1.5rem;padding: 0.8rem 1rem;border-radius:0.6rem;border:1px solid black;"
placeholder="Rag prompt"></textarea>
</div>
<div style="font-size: 1.5rem;margin-top: 1rem;">Embedding:</div>
<div style="display: flex;margin-top: 0.4rem;" id="embeddingPlace">
<selector-component id="embeddingSelector" style="flex:1;" placeholder="- -" mainColor="#000"></selector-component>
<div id="embeddingBlock" style="margin-left: 0.8rem;flex:1;display: none;">
<selector-component id="embeddingFileSelector" autoSelectFirst="true"
placeholder="Select embedding file" mainColor="#000"></selector-component>
</div>
</div>
<div style="font-size: 1.5rem;margin-top: 1rem;">Dataset:</div>
<div style="display: flex;margin-top: 0.4rem;" id="datasetPlace">
<selector-component id="datasetSelector" autoSelectFirst="true" style="flex:1;" placeholder="- -"
mainColor="#000"></selector-component>
<div id="datasetBlock" style="margin-left: 0.8rem;flex:1;display: none;">
<selector-component id="datasetFileSelector" autoSelectFirst="true"
placeholder="Select dataset file" mainColor="#000"></selector-component>
</div>
</div>
<div style="display: none;margin-top: 1rem;" id="config">
<div style="display: flex;justify-content: space-between;align-items: center;font-size: 1.5rem;">
<div>Config:</div>
<div onclick="saveObjectAsJSON()" style="padding: 0.5rem 1.5rem;border: 1px solid black;border-radius: 0.5rem;"
class="clickButton">download config.json
</div>
</div>
<div style="position: relative;">
<img onclick="copyJSON()" style="position: absolute;user-select: none;top:1.5rem;right: 1.5rem;" class="copy"
id="copyIcon" width="18" height="18" src="./media/Copy.svg"/>
<pre style="background-color: #f4f4f4;padding: 10px;border-radius: 0.4rem;overflow-x: auto;"
id="configData"></pre>
</div>
<span id="success" style="color: mediumseagreen;display: none;">Copy Success!</span>
<span id="error"
style="color: darkred;display: none;">Copying failed, you can try clicking the download button!</span>
</div>
<script>
const HFOrg = "gaianet"
const datasetDownloadLink = "https://huggingface.co/datasets/gaianet/paris/resolve/main/"
let offset = 0
let limit = 10
let configData
let modelList = []
let embeddingList = []
let haveNext = true
let selectedModel
let selectedModelFile
let selectedEmbedding
let selectedEmbeddingFile
let selectedDatasetFile
const modelSelector = document.getElementById("modelSelector");
const fileSelector = document.getElementById("fileSelector");
const modelBlock = document.getElementById("modelBlock");
const embeddingSelector = document.getElementById("embeddingSelector");
const embeddingBlock = document.getElementById("embeddingBlock");
const embeddingFileSelector = document.getElementById("embeddingFileSelector");
const datasetSelector = document.getElementById("datasetSelector");
const datasetFileSelector = document.getElementById("datasetFileSelector");
const datasetBlock = document.getElementById("datasetBlock");
const configPlace = document.getElementById("config");
const configFilePlace = document.getElementById("configData");
const systemInput = document.getElementById("systemInput");
const ragInput = document.getElementById("ragInput");
function getModels() {
if (haveNext) {
fetch(`https://code.flows.network/webhook/DsbnEK45sK3NUzFUyZ9C/models?status=published&trace_status=tracing&order=most_likes&offset=${offset}&limit=${limit}`)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
if (data.length > 0) {
if (data.length < limit) {
haveNext = false;
}
data.forEach(item => {
if (item.model_type === "embedding") {
embeddingList.push(item);
} else {
modelList.push(item);
}
})
modelSelector.list = modelList
embeddingSelector.list = embeddingList
if(offset===0){
modelSelector.defaultValue = "TheBloke/Llama-2-7B-Chat-GGUF";
}
offset += limit
} else {
haveNext = false;
}
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
return true;
} else {
return false;
}
}
function getHFDataset() {
fetch(`https://huggingface.co/api/datasets?author=${HFOrg}`).then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
}).then(data => {
datasetSelector.list = data.map(item => {
return {name: item.id.split("/")[1], ...item}
});
})
}
modelSelector.queryMore = getModels;
function selectModel(data) {
if (data) {
selectedModel = data;
systemInput.disabled = false;
ragInput.disabled = false;
modelBlock.style.display = "block";
fileSelector.disabled = false;
embeddingSelector.disabled = false;
embeddingSelector.defaultValue = "second-state/All-MiniLM-L6-v2-Embedding-GGUF";
datasetSelector.disabled = false;
getHFDataset();
fileSelector.list = data.files;
fileSelector.defaultValue = "llama-2-7b-chat.Q5_K_M.gguf";
}
}
modelSelector.changeCallBack = selectModel;
getModels();
function checkValue(data) {
if (data) {
return data;
} else {
return "";
}
}
systemInput.addEventListener("input", generateConfig)
ragInput.addEventListener("input", generateConfig)
function generateConfig() {
configData = JSON.stringify({
"address": "",
"description": selectedModel ? checkValue(selectedModel.summary) : "",
"chat": selectedModelFile ? checkValue(selectedModelFile.hf_download_url) : "",
"prompt_template": selectedModel ? checkValue(selectedModel.prompt_template) : "",
"reverse_prompt": selectedModel ? checkValue(selectedModel.reverse_prompt) : "",
"chat_ctx_size": selectedModel ? checkValue(selectedModel.context_size) : "",
"system_prompt": systemInput.value || "You are a helpful, respectful and honest assistant. Always answer accurately, while being safe.",
"embedding": selectedEmbeddingFile ? checkValue(selectedEmbeddingFile.hf_download_url) : "",
"embedding_collection_name": "default",
"snapshot": selectedDatasetFile ? checkValue(datasetDownloadLink + selectedDatasetFile.name) : "",
"embedding_ctx_size": selectedEmbedding ? checkValue(selectedEmbedding.context_size) : "",
"rag_prompt": ragInput.value || "Use the following pieces of context to answer the user's question.\nIf you don't know the answer, just say that you don't know, don't try to make up an answer.\n----------------\n",
"domain": "gaianet.xyz",
"llamaedge_port": "8080"
}, null, 4)
configPlace.style.display = "block";
configFilePlace.innerText = configData;
}
function setModelFile(data) {
if (data) {
selectedModelFile = data;
generateConfig();
}
}
fileSelector.changeCallBack = setModelFile;
function setEmbedding(data) {
if (data) {
selectedEmbedding = data;
embeddingBlock.style.display = "block";
embeddingFileSelector.list = data.files;
generateConfig();
}
}
embeddingSelector.disabled = true;
embeddingSelector.changeCallBack = setEmbedding;
function setEmbeddingFile(data) {
if (data) {
selectedEmbeddingFile = data;
generateConfig();
}
}
embeddingFileSelector.changeCallBack = setEmbeddingFile;
function setDataset(selectDataSet) {
datasetFileSelector.list = [];
if (selectDataSet) {
datasetBlock.style.display = "block";
fetch(`https://huggingface.co/api/datasets/${selectDataSet.id}`).then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
}).then(data => {
if (data && data.siblings) {
let datasetList = []
data.siblings.forEach(obj => {
if (obj.rfilename.endsWith('.snapshot')) {
datasetList.push({name: obj.rfilename})
}
});
datasetFileSelector.list = datasetList;
}
})
}
}
datasetSelector.disabled = true;
datasetSelector.changeCallBack = setDataset;
function setDatasetFile(data) {
if (data) {
selectedDatasetFile = data;
generateConfig();
}
}
datasetFileSelector.changeCallBack = setDatasetFile;
function copyJSON() {
navigator.clipboard.writeText(configData).then(function () {
const success = document.getElementById("success")
success.style.display = "inline";
setTimeout(() => {
success.style.display = "none";
}, 2000)
}, function (err) {
const error = document.getElementById("error")
error.style.display = "inline";
setTimeout(() => {
error.style.display = "none";
}, 2000)
});
}
function saveObjectAsJSON() {
const blob = new Blob([configData], {type: 'application/json'});
const a = document.createElement('a');
a.style.display = 'none';
a.download = 'config.json';
const url = window.URL.createObjectURL(blob);
a.href = url;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}
</script>
</body>
</html>