Skip to content

Commit bcdb7a2

Browse files
MaggotHATEngxson
andauthored
server: (web UI) Add samplers sequence customization (ggml-org#10255)
* Samplers sequence: simplified and input field. * Removed unused function * Modify and use `settings-modal-short-input` * rename "name" --> "label" --------- Co-authored-by: Xuan Son Nguyen <[email protected]>
1 parent f245cc2 commit bcdb7a2

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

examples/server/public/index.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
212212
<details class="collapse collapse-arrow bg-base-200 mb-2 overflow-visible">
213213
<summary class="collapse-title font-bold">Other sampler settings</summary>
214214
<div class="collapse-content">
215+
<!-- Samplers queue -->
216+
<settings-modal-short-input label="Samplers queue" :config-key="'samplers'" :config-default="configDefault" :config-info="configInfo" v-model="config.samplers"></settings-modal-short-input>
217+
<!-- Samplers -->
215218
<template v-for="configKey in ['dynatemp_range', 'dynatemp_exponent', 'typical_p', 'xtc_probability', 'xtc_threshold']">
216219
<settings-modal-short-input :config-key="configKey" :config-default="configDefault" :config-info="configInfo" v-model="config[configKey]" />
217220
</template>
@@ -231,6 +234,7 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
231234
<summary class="collapse-title font-bold">Advanced config</summary>
232235
<div class="collapse-content">
233236
<label class="form-control mb-2">
237+
<!-- Custom parameters input -->
234238
<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>
235239
<textarea class="textarea textarea-bordered h-24" placeholder="Example: { &quot;mirostat&quot;: 1, &quot;min_p&quot;: 0.1 }" v-model="config.custom"></textarea>
236240
</label>
@@ -253,7 +257,7 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
253257
<label class="input input-bordered join-item grow flex items-center gap-2 mb-2">
254258
<!-- Show help message on hovering on the input label -->
255259
<div class="dropdown dropdown-hover">
256-
<div tabindex="0" role="button" class="font-bold">{{ configKey }}</div>
260+
<div tabindex="0" role="button" class="font-bold">{{ label || configKey }}</div>
257261
<div class="dropdown-content menu bg-base-100 rounded-box z-10 w-64 p-2 shadow mt-4">
258262
{{ configInfo[configKey] || '(no help message available)' }}
259263
</div>
@@ -282,6 +286,7 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
282286
apiKey: '',
283287
systemMessage: 'You are a helpful assistant.',
284288
// make sure these default values are in sync with `common.h`
289+
samplers: 'dkypmxt',
285290
temperature: 0.8,
286291
dynatemp_range: 0.0,
287292
dynatemp_exponent: 1.0,
@@ -305,6 +310,7 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
305310
const CONFIG_INFO = {
306311
apiKey: 'Set the API Key if you are using --api-key option for the server.',
307312
systemMessage: 'The starting message that defines how model should behave.',
313+
samplers: 'The order at which samplers are applied, in simplified way. Default is "dkypmxt": dry->top_k->typ_p->top_p->min_p->xtc->temperature',
308314
temperature: 'Controls the randomness of the generated text by affecting the probability distribution of the output tokens. Higher = more random, lower = more focused.',
309315
dynatemp_range: 'Addon for the temperature sampler. The added value to the range of dynamic temperature, which adjusts probabilities by entropy of tokens.',
310316
dynatemp_exponent: 'Addon for the temperature sampler. Smoothes out the probability redistribution based on the most probable token.',
@@ -352,10 +358,16 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
352358
{ props: ["source"] }
353359
);
354360

355-
// inout field to be used by settings modal
361+
// input field to be used by settings modal
356362
const SettingsModalShortInput = defineComponent({
357363
template: document.getElementById('settings-modal-short-input').innerHTML,
358-
props: ['configKey', 'configDefault', 'configInfo', 'modelValue'],
364+
props: {
365+
label: { type: String, required: false },
366+
configKey: String,
367+
configDefault: Object,
368+
configInfo: Object,
369+
modelValue: [Object, String, Number],
370+
},
359371
});
360372

361373
// coversations is stored in localStorage
@@ -546,6 +558,7 @@ <h3 class="text-lg font-bold mb-6">Settings</h3>
546558
],
547559
stream: true,
548560
cache_prompt: true,
561+
samplers: this.config.samplers,
549562
temperature: this.config.temperature,
550563
dynatemp_range: this.config.dynatemp_range,
551564
dynatemp_exponent: this.config.dynatemp_exponent,

examples/server/server.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -927,14 +927,22 @@ struct server_context {
927927

928928
{
929929
const auto & samplers = data.find("samplers");
930-
if (samplers != data.end() && samplers->is_array()) {
931-
std::vector<std::string> sampler_names;
932-
for (const auto & name : *samplers) {
933-
if (name.is_string()) {
934-
sampler_names.emplace_back(name);
930+
if (samplers != data.end()) {
931+
if (samplers->is_array()) {
932+
std::vector<std::string> sampler_names;
933+
for (const auto & name : *samplers) {
934+
if (name.is_string()) {
935+
sampler_names.emplace_back(name);
936+
}
937+
}
938+
slot.sparams.samplers = common_sampler_types_from_names(sampler_names, false);
939+
} else if (samplers->is_string()){
940+
std::string sampler_string;
941+
for (const auto & name : *samplers) {
942+
sampler_string += name;
935943
}
944+
slot.sparams.samplers = common_sampler_types_from_chars(sampler_string);
936945
}
937-
slot.sparams.samplers = common_sampler_types_from_names(sampler_names, false);
938946
} else {
939947
slot.sparams.samplers = default_sparams.samplers;
940948
}

0 commit comments

Comments
 (0)