Add seed input field for OpenAI settings #1412

This commit is contained in:
Cohee 2023-11-30 02:54:52 +02:00
parent 6abd0b4b75
commit e9ad55aef2
3 changed files with 26 additions and 0 deletions

View File

@ -737,6 +737,17 @@
<div id="openai_proxy_password_show" title="Peek a password" class="menu_button fa-solid fa-eye-slash fa-fw"></div>
</div>
</div>
<div data-newbie-hidden class="range-block" data-source="openai,openrouter">
<div class="range-block-title justifyLeft" data-i18n="Seed">
Seed
</div>
<div class="toggle-description justifyLeft" data-i18n="Set to get deterministic results. Use -1 for random seed.">
Set to get deterministic results. Use -1 for random seed.
</div>
<div class="wide100p">
<input type="number" id="seed_openai" name="seed_openai" class="text_pole" min="-1" max="2147483647" value="-1">
</div>
</div>
<div data-newbie-hidden class="range-block" data-source="openai,claude">
<div class="range-block-title justifyLeft">
<label for="legacy_streaming" class="checkbox_label">

View File

@ -229,6 +229,7 @@ const default_settings = {
squash_system_messages: false,
image_inlining: false,
bypass_status_check: false,
seed: -1,
};
const oai_settings = {
@ -282,6 +283,7 @@ const oai_settings = {
squash_system_messages: false,
image_inlining: false,
bypass_status_check: false,
seed: -1,
};
let openai_setting_names;
@ -1557,6 +1559,10 @@ async function sendOpenAIRequest(type, messages, signal) {
generate_data['stop_tokens'] = [name1 + ':', oai_settings.new_chat_prompt, oai_settings.new_group_chat_prompt];
}
if ((isOAI || isOpenRouter) && oai_settings.seed >= 0) {
generate_data['seed'] = oai_settings.seed;
}
const generate_url = '/generate_openai';
const response = await fetch(generate_url, {
method: 'POST',
@ -2415,6 +2421,7 @@ function loadOpenAISettings(data, settings) {
$('#top_k_openai').val(oai_settings.top_k_openai);
$('#top_k_counter_openai').val(Number(oai_settings.top_k_openai).toFixed(0));
$('#seed_openai').val(oai_settings.seed);
if (settings.reverse_proxy !== undefined) oai_settings.reverse_proxy = settings.reverse_proxy;
$('#openai_reverse_proxy').val(oai_settings.reverse_proxy);
@ -2594,6 +2601,7 @@ async function saveOpenAIPreset(name, settings, triggerUi = true) {
use_alt_scale: settings.use_alt_scale,
squash_system_messages: settings.squash_system_messages,
image_inlining: settings.image_inlining,
seed: settings.seed,
};
const savePresetSettings = await fetch(`/api/presets/save-openai?name=${name}`, {
@ -2953,6 +2961,7 @@ function onSettingsPresetChange() {
use_alt_scale: ['#use_alt_scale', 'use_alt_scale', true],
squash_system_messages: ['#squash_system_messages', 'squash_system_messages', true],
image_inlining: ['#openai_image_inlining', 'image_inlining', true],
seed: ['#seed_openai', 'seed', false],
};
const presetName = $('#settings_preset_openai').find(":selected").text();
@ -3768,6 +3777,11 @@ $(document).ready(async function () {
saveSettingsDebounced();
});
$('#seed_openai').on('input', function () {
oai_settings.seed = Number($(this).val());
saveSettingsDebounced();
});
$(document).on('input', '#openai_settings .autoSetHeight', function () {
resetScrollHeight($(this));
});

View File

@ -3303,6 +3303,7 @@ app.post("/generate_openai", jsonParser, function (request, response_generate_op
"top_k": request.body.top_k,
"stop": isTextCompletion === false ? request.body.stop : undefined,
"logit_bias": request.body.logit_bias,
"seed": request.body.seed,
...bodyParams,
}),
signal: controller.signal,