forked from SkywardAI/voyager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_production_env.html
376 lines (341 loc) · 13.8 KB
/
generate_production_env.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<!--
coding=utf-8
Copyright [2024] [SkywardAI]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Generate Voyager Production Env</title>
<style type="text/css">
* {
font-family: ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";
--union-height: 30px;
}
section {
padding: 20px;
width: fit-content;
box-sizing: border-box;
}
div {
font-size: 20px;
box-sizing: border-box;
}
.description {
font-size: 17px;
color: gray;
margin-bottom: 20px;
line-height: 25px;
}
code {
background-color: rgb(221 221 221 / 60%);
padding: 0px 5px;
border-radius: 6px;
}
.one-line {
display: flex;
align-items: center;
height: var(--union-height);
width: 600px;
max-width: 100dvw;
margin-bottom: 10px;
}
.one-line:hover > *:not(input[type="text"]) {
border-bottom: 1px solid lightgray;
}
.one-line:last-child {
margin-bottom: unset;
}
.one-line > * {
margin-left: 0;
}
.one-line > .title {
flex-basis: 70%;
user-select: none;
}
input {
height: var(--union-height);
}
input[type="checkbox"] {
width: calc(var(--union-height) * 0.8);
height: calc(var(--union-height) * 0.8);
}
input[type="text"]:focus {
outline: none;
}
.one-line.api-index {
margin-left: var(--union-height);
}
.one-line.sub-api {
margin-left: calc(var(--union-height) * 2);
}
.gen-file {
width: 200px;
height: 50px;
border-radius: 10px;
font-size: 17px;
background-color: dodgerblue;
color: white;
border: none;
}
.gen-file:hover {
cursor: pointer;
background-color: rgb(0, 113, 226);
}
</style>
<script type="text/javascript">
function load() {
"use strict";
const all_api_indexes = document.querySelectorAll('.one-line.api.api-index > input[type="checkbox"]');
const all_sub_apis = document.querySelectorAll('.one-line.api.sub-api > input[type="checkbox"]');
function toggleAllAPIsAvailability(enabled) {
[...all_api_indexes, ...all_sub_apis].forEach(e=>{
e.checked = enabled;
e.disabled = enabled;
})
}
document.getElementById("enable-all-apis").onchange = (evt) => {
const enabled = evt.target.checked;
toggleAllAPIsAvailability(enabled);
}
all_api_indexes.forEach(e=>{
const name = e.name;
const sub_apis = Array.from(all_sub_apis).filter(s=>s.name.startsWith(name))
e.onchange = evt => {
const enabled = evt.target.checked;
sub_apis.forEach(s=>{
s.checked = enabled;
s.disabled = enabled;
})
}
})
toggleAllAPIsAvailability(true);
const all_https_input = document.querySelectorAll(".one-line.https > input[type='text']")
function toggleHttpsInputAvailability(enabled) {
all_https_input.forEach(e=>e.disabled = !enabled);
}
document.getElementById('enable-http').onchange = evt => {
const enabled = evt.target.checked;
toggleHttpsInputAvailability(enabled)
}
toggleHttpsInputAvailability(false);
}
function saveEnv(evt) {
evt.preventDefault();
let ALLOW_ORIGIN = evt.target.allow_origin.value;
if(!ALLOW_ORIGIN || ALLOW_ORIGIN === '*') {
ALLOW_ORIGIN = '*';
} else {
if(!/^(http|https)/.test(ALLOW_ORIGIN)) {
ALLOW_ORIGIN = 'https://'+ALLOW_ORIGIN;
}
if(/\/$/.test(ALLOW_ORIGIN)) {
ALLOW_ORIGIN = ALLOW_ORIGIN.substring(0, ALLOW_ORIGIN.length - 1);
}
}
const STATIC_API_KEY_ENABLED = +evt.target.static_api_key_enabled.checked;
const ENABLE_PLUGIN = +evt.target.enable_plugin.checked;
const ENABLE_HTTPS = +evt.target.https_enabled.checked;
const HTTPS_KEY_PATH = evt.target.https_key.value || "*";
const HTTPS_CERT_PATH = evt.target.https_certificate.value || "*";
const HTTPS_CA_PATH = evt.target.https_ca.value || "*";
const SYSTEM_INSTRUCTION = evt.target.system_instruction.value || "*";
const LOAD_DEFAULT_DATASET = +evt.target.load_default_dataset.checked;
const DEFAULT_DATASET_NAME = evt.target.default_dataset_name.value || "production_dataset";
let AVAILABLE_APIS = ''
if(evt.target.available_api_all.checked) {
AVAILABLE_APIS = 'ALL'
} else {
AVAILABLE_APIS += +evt.target.available_api_index_swagger.checked;
AVAILABLE_APIS += +evt.target.available_api_index_stats.checked;
AVAILABLE_APIS += +evt.target.available_api_index_healthy.checked;
AVAILABLE_APIS += '.';
AVAILABLE_APIS += +evt.target.available_api_inference_normal.checked;
AVAILABLE_APIS += +evt.target.available_api_inference_rag.checked;
AVAILABLE_APIS += '.';
AVAILABLE_APIS += +evt.target.available_api_token.checked;
AVAILABLE_APIS += '.';
AVAILABLE_APIS += +evt.target.available_api_embedding_index.checked;
AVAILABLE_APIS += +evt.target.available_api_embedding_dataset.checked;
AVAILABLE_APIS += '.';
AVAILABLE_APIS += +evt.target.available_api_version.checked;
}
const env_string =
`ALLOW_ORIGIN=${ALLOW_ORIGIN||'*'}
STATIC_API_KEY_ENABLED=${STATIC_API_KEY_ENABLED}
ENABLE_PLUGIN=${ENABLE_PLUGIN}
ENABLE_HTTPS=${ENABLE_HTTPS}
HTTPS_KEY_PATH=${HTTPS_KEY_PATH}
HTTPS_CERT_PATH=${HTTPS_CERT_PATH}
HTTPS_CA_PATH=${HTTPS_CA_PATH}
SYSTEM_INSTRUCTION=${SYSTEM_INSTRUCTION}
AVAILABLE_APIS=${AVAILABLE_APIS}
LOAD_DEFAULT_DATASET=${LOAD_DEFAULT_DATASET}
DEFAULT_DATASET_NAME=${DEFAULT_DATASET_NAME}`;
const env_file = new Blob([env_string], {type: 'text/plain'});
const url = URL.createObjectURL(env_file);
const download_link = document.createElement('a')
download_link.href = url;
download_link.download = `.env.production`
download_link.click();
URL.revokeObjectURL(url);
}
window.onload = load;
</script>
</head>
<body>
<form onsubmit="saveEnv(event)">
<section>
<h3>Allow Origin</h3>
<div class="description">Allow only one origin can access the APIs</div>
<div class="one-line">
<div class="title">Allow origin name: </div>
<input type="text" name="allow_origin">
</div>
</section>
<section>
<h3>Https Features</h3>
<div class="description">
Enable https and specify path to <code>Key</code> and <code>Certificate</code> and/or <code>CA</code> files<br>
Only with <code>pem</code> extension is available.<br>
The <code>CA</code> part is optional and other parts are required, otherwise this function won't work.
</div>
<div class="one-line">
<div class="title">Enable Https:</div>
<input type="checkbox" name="https_enabled" id="enable-http">
</div>
<div class="one-line https">
<div class="title">Path to <code>Key</code>:</div>
<input type="text" name="https_key">
</div>
<div class="one-line https">
<div class="title">Path to <code>Certificate</code>:</div>
<input type="text" name="https_certificate">
</div>
<div class="one-line https">
<div class="title">Path to <code>CA</code>:</div>
<input type="text" name="https_ca">
</div>
</section>
<section>
<h3>Enable Plugin</h3>
<div class="description">
Enables plugin to modify the action of <code>/v1/chat/completions</code>.<br>
Please enable this and write your own plugin in <code>/tools/plugin.js</code>
</div>
<div class="one-line">
<div class="title">Enables plugins: </div>
<input type="checkbox" name="enable_plugin">
</div>
</section>
<section>
<h3>System Instruction</h3>
<div class="description">
Specify the default instruction for AI, won't work when use OpenAI like request format.
</div>
<div class="one-line">
<div class="title">System instruction: </div>
<input type="text" name="system_instruction">
</div>
</section>
<section>
<h3>Default Dataset</h3>
<div class="description">
Set load default dataset or not, and specify dataset name.<br>
Please implement your own dataset generator in <code>/tools/plugin.js</code> use the function <code>loadDefaultDataset()</code>
</div>
<div class="one-line">
<div class="title">Enable load default dataset: </div>
<input type="checkbox" name="load_default_dataset">
</div><div class="one-line">
<div class="title">Set default dataset name: </div>
<input type="text" name="default_dataset_name" placeholder="production_dataset">
</div>
</section>
<section>
<h3>Static API-Key Enabled</h3>
<div class="description">
If enabled, instead of query api-key from database, a text comparation will be conducted on provided API key.<br>
Remember to include API key in your server global environment named <code>STATIC_API_KEY</code>.<br>
It should be sent through header in the format of <code>Authorization: Bearer <your-api-key></code></div>
<div class="one-line">
<div class="title">Enable static API-Key:</div>
<input type="checkbox" name="static_api_key_enabled">
</div>
</section>
<section>
<h3>APIs Available</h3>
<div class="description">Set available APIs in your server.</div>
<div class="one-line">
<div class="title">Enable All APIs</div>
<input type="checkbox" name="available_api_all" id="enable-all-apis" checked>
</div>
<div class="one-line api api-index">
<div class="title">Enable All Index APIs</div>
<input type="checkbox" name="available_api_index">
</div>
<div class="one-line api sub-api">
<div class="title">Enable Route Docs</div>
<input type="checkbox" name="available_api_index_swagger">
</div>
<div class="one-line api sub-api">
<div class="title">Enable Server Stats</div>
<input type="checkbox" name="available_api_index_stats">
</div>
<div class="one-line api sub-api">
<div class="title">Enable Healthy Check</div>
<input type="checkbox" name="available_api_index_healthy">
</div>
<div class="one-line api api-index">
<div class="title">Enable All Inference APIs</div>
<input type="checkbox" name="available_api_inference">
</div>
<div class="one-line api sub-api">
<div class="title">Enable Inference Completions</div>
<input type="checkbox" name="available_api_inference_normal">
</div>
<div class="one-line api sub-api">
<div class="title">Enable RAG Inference Completions</div>
<input type="checkbox" name="available_api_inference_rag">
</div>
<div class="one-line api api-index">
<div class="title">Enable Token API</div>
<input type="checkbox" name="available_api_token">
</div>
<div class="one-line api api-index">
<div class="title">Enable Embedding API</div>
<input type="checkbox" name="available_api_embedding">
</div>
<div class="one-line api sub-api">
<div class="title">Enable Calculate Embeddings</div>
<input type="checkbox" name="available_api_embedding_index">
</div>
<div class="one-line api sub-api">
<div class="title">Enable Dataset Upload</div>
<input type="checkbox" name="available_api_embedding_dataset">
</div>
<div class="one-line api api-index">
<div class="title">Enable Version API</div>
<input type="checkbox" name="available_api_version">
</div>
</section>
<section>
<h3>Generate & Download Env File</h3>
<div class="description">
Remember to rename your env file to <code>.env.production</code><br>
(The <code>.</code> at the most beginning might disappear due to browser security policy)<br>
And replace the existed <code>.env.production</code> file in root dir.</div>
<button type="submit" class="gen-file">Generate Env File</button>
</section>
</form>
</body>
</html>