Skip to content

Commit 505f332

Browse files
MaggotHATEngxson
andauthored
server : (web UI) Add back sampler settings (#10239)
* Add back samplers to server * Added tooltips with basic information * Fixed stretching of input fields. * use component for settings input, move help msg to tooltips --------- Co-authored-by: Xuan Son Nguyen <[email protected]>
1 parent 160687b commit 505f332

File tree

1 file changed

+97
-9
lines changed

1 file changed

+97
-9
lines changed

examples/server/public/index.html

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,38 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
200200
<div class="label">System Message</div>
201201
<textarea class="textarea textarea-bordered h-24" :placeholder="'Default: ' + configDefault.systemMessage" v-model="config.systemMessage"></textarea>
202202
</label>
203-
<template v-for="key in ['temperature', 'top_k', 'top_p', 'min_p', 'max_tokens']">
204-
<label class="input input-bordered flex items-center gap-2 mb-2">
205-
<b>{{ key }}</b>
206-
<input type="text" class="grow" :placeholder="'Default: ' + (configDefault[key] || 'none')" v-model="config[key]" />
207-
</label>
203+
<template v-for="configKey in ['temperature', 'top_k', 'top_p', 'min_p', 'max_tokens']">
204+
<settings-modal-numeric-input :config-key="configKey" :config-default="configDefault" :config-info="configInfo" v-model="config[configKey]" />
208205
</template>
209206
<!-- TODO: add more sampling-related configs, please regroup them into different "collapse" sections -->
210-
<div class="collapse collapse-arrow bg-base-200 mb-2">
211-
<input type="checkbox" />
212-
<div class="collapse-title font-bold">Advanced config</div>
207+
<!-- Section: Other sampler settings -->
208+
<details class="collapse collapse-arrow bg-base-200 mb-2 overflow-visible">
209+
<summary class="collapse-title font-bold">Other sampler settings</summary>
210+
<div class="collapse-content">
211+
<template v-for="configKey in ['dynatemp_range', 'dynatemp_exponent', 'typical_p', 'xtc_probability', 'xtc_threshold']">
212+
<settings-modal-numeric-input :config-key="configKey" :config-default="configDefault" :config-info="configInfo" v-model="config[configKey]" />
213+
</template>
214+
</div>
215+
</details>
216+
<!-- Section: Penalties settings -->
217+
<details class="collapse collapse-arrow bg-base-200 mb-2 overflow-visible">
218+
<summary class="collapse-title font-bold">Penalties settings</summary>
219+
<div class="collapse-content">
220+
<template v-for="configKey in ['repeat_last_n', 'repeat_penalty', 'presence_penalty', 'frequency_penalty', 'dry_multiplier', 'dry_base', 'dry_allowed_length', 'dry_penalty_last_n']">
221+
<settings-modal-numeric-input :config-key="configKey" :config-default="configDefault" :config-info="configInfo" v-model="config[configKey]" />
222+
</template>
223+
</div>
224+
</details>
225+
<!-- Section: Advanced config -->
226+
<details class="collapse collapse-arrow bg-base-200 mb-2 overflow-visible">
227+
<summary class="collapse-title font-bold">Advanced config</summary>
213228
<div class="collapse-content">
214229
<label class="form-control mb-2">
215230
<div class="label inline">Custom JSON config (For more info, refer to <a class="underline" href="https://github.com/ggerganov/llama.cpp/blob/master/examples/server/README.md" target="_blank" rel="noopener noreferrer">server documentation</a>)</div>
216231
<textarea class="textarea textarea-bordered h-24" placeholder="Example: { &quot;mirostat&quot;: 1, &quot;min_p&quot;: 0.1 }" v-model="config.custom"></textarea>
217232
</label>
218233
</div>
219-
</div>
234+
</details>
220235
</div>
221236

222237
<!-- action buttons -->
@@ -229,6 +244,21 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
229244
</dialog>
230245
</div>
231246

247+
<!-- Template to be used by settings modal -->
248+
<template id="settings-modal-numeric-input">
249+
<label class="input input-bordered join-item grow flex items-center gap-2 mb-2">
250+
<!-- Show help message on hovering on the input label -->
251+
<div class="dropdown dropdown-hover">
252+
<div tabindex="0" role="button" class="font-bold">{{ configKey }}</div>
253+
<div class="dropdown-content menu bg-base-100 rounded-box z-10 w-64 p-2 shadow mt-4">
254+
{{ configInfo[configKey] || '(no help message available)' }}
255+
</div>
256+
</div>
257+
<!-- Here we forward v-model from parent to child component, see: https://stackoverflow.com/questions/47311936/v-model-and-child-components -->
258+
<input type="text" class="grow" :placeholder="'Default: ' + (configDefault[configKey] || 'none')" :value="modelValue" @input="$emit('update:modelValue', $event.target.value)" />
259+
</label>
260+
</template>
261+
232262
<script src="./deps_markdown-it.js"></script>
233263
<script type="module">
234264
import { createApp, defineComponent, shallowRef, computed, h } from './deps_vue.esm-browser.js';
@@ -245,12 +275,48 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
245275
systemMessage: 'You are a helpful assistant.',
246276
// make sure these default values are in sync with `common.h`
247277
temperature: 0.8,
278+
dynatemp_range: 0.0,
279+
dynatemp_exponent: 1.0,
248280
top_k: 40,
249281
top_p: 0.95,
250282
min_p: 0.05,
283+
xtc_probability: 0.0,
284+
xtc_threshold: 0.1,
285+
typical_p: 1.0,
286+
repeat_last_n: 64,
287+
repeat_penalty: 1.0,
288+
presence_penalty: 0.0,
289+
frequency_penalty: 0.0,
290+
dry_multiplier: 0.0,
291+
dry_base: 1.75,
292+
dry_allowed_length: 2,
293+
dry_penalty_last_n: -1,
251294
max_tokens: -1,
252295
custom: '', // custom json-stringified object
253296
};
297+
const CONFIG_INFO = {
298+
apiKey: '',
299+
systemMessage: 'The starting message that defines how model should behave.',
300+
temperature: 'Controls the randomness of the generated text by affecting the probability distribution of the output tokens. Higher = more random, lower = more focused.',
301+
dynatemp_range: 'Addon for the temperature sampler. The added value to the range of dynamic temperature, which adjusts probabilities by entropy of tokens.',
302+
dynatemp_exponent: 'Addon for the temperature sampler. Smoothes out the probability redistribution based on the most probable token.',
303+
top_k: 'Keeps only k top tokens.',
304+
top_p: 'Limits tokens to those that together have a cumulative probability of at least p',
305+
min_p: 'Limits tokens based on the minimum probability for a token to be considered, relative to the probability of the most likely token.',
306+
xtc_probability: 'XTC sampler cuts out top tokens; this parameter controls the chance of cutting tokens at all. 0 disables XTC.',
307+
xtc_threshold: 'XTC sampler cuts out top tokens; this parameter controls the token probability that is required to cut that token.',
308+
typical_p: 'Sorts and limits tokens based on the difference between log-probability and entropy.',
309+
repeat_last_n: 'Last n tokens to consider for penalizing repetition',
310+
repeat_penalty: 'Controls the repetition of token sequences in the generated text',
311+
presence_penalty: 'Limits tokens based on whether they appear in the output or not.',
312+
frequency_penalty: 'Limits tokens based on how often they appear in the output.',
313+
dry_multiplier: 'DRY sampling reduces repetition in generated text even across long contexts. This parameter sets the DRY sampling multiplier.',
314+
dry_base: 'DRY sampling reduces repetition in generated text even across long contexts. This parameter sets the DRY sampling base value.',
315+
dry_allowed_length: 'DRY sampling reduces repetition in generated text even across long contexts. This parameter sets the allowed length for DRY sampling.',
316+
dry_penalty_last_n: 'DRY sampling reduces repetition in generated text even across long contexts. This parameter sets DRY penalty for the last n tokens.',
317+
max_tokens: 'The maximum number of token per output.',
318+
custom: '', // custom json-stringified object
319+
};
254320
// config keys having numeric value (i.e. temperature, top_k, top_p, etc)
255321
const CONFIG_NUMERIC_KEYS = Object.entries(CONFIG_DEFAULT).filter(e => isNumeric(e[1])).map(e => e[0]);
256322
// list of themes supported by daisyui
@@ -269,6 +335,12 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
269335
{ props: ["source", "options", "plugins"] }
270336
);
271337

338+
// inout field to be used by settings modal
339+
const SettingsModalNumericInput = defineComponent({
340+
template: document.getElementById('settings-modal-numeric-input').innerHTML,
341+
props: ['configKey', 'configDefault', 'configInfo', 'modelValue'],
342+
});
343+
272344
// coversations is stored in localStorage
273345
// format: { [convId]: { id: string, lastModified: number, messages: [...] } }
274346
// convId is a string prefixed with 'conv-'
@@ -359,6 +431,7 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
359431
const mainApp = createApp({
360432
components: {
361433
VueMarkdown,
434+
SettingsModalNumericInput,
362435
},
363436
data() {
364437
return {
@@ -376,6 +449,7 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
376449
// const
377450
themes: THEMES,
378451
configDefault: {...CONFIG_DEFAULT},
452+
configInfo: {...CONFIG_INFO},
379453
}
380454
},
381455
computed: {},
@@ -452,8 +526,22 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
452526
stream: true,
453527
cache_prompt: true,
454528
temperature: this.config.temperature,
529+
dynatemp_range: this.config.dynatemp_range,
530+
dynatemp_exponent: this.config.dynatemp_exponent,
455531
top_k: this.config.top_k,
456532
top_p: this.config.top_p,
533+
min_p: this.config.min_p,
534+
typical_p: this.config.typical_p,
535+
xtc_probability: this.config.xtc_probability,
536+
xtc_threshold: this.config.xtc_threshold,
537+
repeat_last_n: this.config.repeat_last_n,
538+
repeat_penalty: this.config.repeat_penalty,
539+
presence_penalty: this.config.presence_penalty,
540+
frequency_penalty: this.config.frequency_penalty,
541+
dry_multiplier: this.config.dry_multiplier,
542+
dry_base: this.config.dry_base,
543+
dry_allowed_length: this.config.dry_allowed_length,
544+
dry_penalty_last_n: this.config.dry_penalty_last_n,
457545
max_tokens: this.config.max_tokens,
458546
...(this.config.custom.length ? JSON.parse(this.config.custom) : {}),
459547
...(this.config.apiKey ? { api_key: this.config.apiKey } : {}),

0 commit comments

Comments
 (0)