Skip to content

Commit 83763e6

Browse files
committed
Fixed empty strings processing in some UI input fields
* `Shift` + `Enter` always adds newline, albeit crudely implemented
1 parent 188a6ad commit 83763e6

File tree

2 files changed

+8963
-27
lines changed

2 files changed

+8963
-27
lines changed

UI_simple.h

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@ std::string getStringFromJson(std::string fileName, std::string stringName){
186186
return "NULL";
187187
}
188188

189+
static void buttonOnTextChanges(std::string& stringBase, std::string& stringChanged) {
190+
if (stringBase != stringChanged) {
191+
if (ImGui::Button("Apply")) {
192+
stringBase = stringChanged;
193+
}
194+
}
195+
}
196+
197+
static void reserveEmpty(std::string& stringBase) {
198+
if (stringBase.empty()) {
199+
stringBase.reserve(1048576);
200+
stringBase.resize(1, ' ');
201+
}
202+
}
203+
189204
static void sliderTemp(float& temp, float& default_temp)
190205
{
191206
{
@@ -2388,7 +2403,7 @@ struct chatUI{
23882403

23892404
if (localSettings.inputInstructFile == "NULL" && localSettings.instructFileFromJson != "NULL") ImGui::TextWrapped( "This model has an instruct file set for it in config. Prompt and antiprompt will not be used!" );
23902405

2391-
if (!localSettings.checkInputPrompt() | !localSettings.checkInputAntiprompt() | !localSettings.checkInputAntiCFG() | !localSettings.checkInputSuffix() | !localSettings.checkInputPrefix()) {
2406+
//if (!localSettings.checkAll()) {
23922407

23932408
if (ImGui::Button("Apply to config")) {
23942409
//localSettings.getFromJson("config.json");
@@ -2402,7 +2417,7 @@ struct chatUI{
24022417

24032418

24042419
//ImGui::Separator();
2405-
}
2420+
//}
24062421

24072422

24082423
if (localSettings.inputInstructFile == "NULL") {
@@ -2551,21 +2566,18 @@ struct chatUI{
25512566
float initWidth = baseWidth * 0.8f;
25522567
//ImGui::EndChild();
25532568
ImGui::InputTextMultiline("Prompt", &localSettings.inputPrompt, ImVec2(initWidth, ImGui::GetTextLineHeight() * 15)); ImGui::SameLine(); HelpMarker( "Prompt can be used as a start of the dialog, providing context and/or format of dialog." );
2569+
25542570
ImGui::InputTextMultiline("Antiprompt", &localSettings.inputAntiprompt, ImVec2(initWidth, ImGui::GetTextLineHeight() * 3)); ImGui::SameLine(); HelpMarker( "Antiprompt is needed to control when to stop generating and wait for your input." );
2555-
// if (ImGui::Button("Apply antiprompt")) {
2556-
// localSettings.inputAntiprompt = inputAntiprompt;
2557-
// } ImGui::SameLine(); if (ImGui::Button("Clear antiprompt")) {
2558-
// localSettings.inputAntiprompt = "NULL";
2559-
// }
2560-
ImGui::InputTextMultiline("Prefix", &localSettings.inputPrefix, ImVec2(initWidth, ImGui::GetTextLineHeight() * 3)); ImGui::SameLine(); HelpMarker( "Prefix sets your character for each input." );
2561-
2571+
2572+
ImGui::InputTextMultiline("Prefix", &localSettings.inputPrefix, ImVec2(initWidth, ImGui::GetTextLineHeight() * 3)); ImGui::SameLine(); HelpMarker( "Prefix sets your character for each input." );
2573+
25622574
ImGui::InputTextMultiline("Suffix", &localSettings.inputSuffix, ImVec2(initWidth, ImGui::GetTextLineHeight() * 3)); ImGui::SameLine(); HelpMarker( "Suffix is added after your prompt - can be used to instantly set the charater for NN." );
2563-
2564-
ImGui::InputText("Grammar file", &inputGrammar); ImGui::SameLine(); HelpMarker( "Grammars are more strict rules that help fomratting teh dialog." );
2575+
2576+
ImGui::InputText("Grammar file", &inputGrammar); ImGui::SameLine(); HelpMarker( "Grammars are more strict rules that help fomratting teh dialog." );
25652577
if (ImGui::Button("Choose grammar")) {
25662578
inputGrammar = openGrammar();
25672579
}
2568-
2580+
25692581
ImGui::InputTextMultiline("CFG Antiprompt", &localSettings.inputAntiCFG, ImVec2(initWidth, ImGui::GetTextLineHeight() * 5)); ImGui::SameLine(); HelpMarker( "CFG Antiprompt is used to guide the output by defining what should NOT be in it. cfg_scale must be higher than 1.0 to activate CFG." );
25702582
// if (ImGui::Button("Apply CFG antiprompt")) {
25712583
// localSettings.inputAntiCFG = inputAntiCFG;
@@ -3173,7 +3185,7 @@ struct chatUI{
31733185
if (ImGui::BeginMenu("Settings..."))
31743186
{
31753187

3176-
ImGui::CheckboxFlags("Send messages by Enter", &inputFlags, ImGuiInputTextFlags_CtrlEnterForNewLine);
3188+
ImGui::CheckboxFlags("Send messages with Enter", &inputFlags, ImGuiInputTextFlags_CtrlEnterForNewLine);
31773189

31783190
ImGui::EndMenu();
31793191
}
@@ -3821,19 +3833,6 @@ struct chatUI{
38213833
modelToConfig(localSettings.modelFromJson);
38223834

38233835
fillImagesData();
3824-
3825-
//inputPrompt = localSettings.params.prompt;
3826-
3827-
//n_ctx_idx = sqrt( localSettings.params.n_ctx / 2048 );
3828-
3829-
// if(localSettings.params.antiprompt.size()) inputAntiprompt = localSettings.params.antiprompt[0];
3830-
// #if GGML_OLD_FORMAT
3831-
// inputAntiCFG = localSettings.params.cfg_negative_prompt;
3832-
// #elif GGML_USE_VULKAN2
3833-
// inputAntiCFG = localSettings.params.sampling_params.cfg_negative_prompt;
3834-
// #else
3835-
// inputAntiCFG = localSettings.params.sparams.cfg_negative_prompt;
3836-
// #endif
38373836

38383837
switch (themeIdx)
38393838
{
@@ -3843,7 +3842,7 @@ struct chatUI{
38433842
case 3: retroTheme(); break;
38443843
default: retroTheme(); break;
38453844
}
3846-
3845+
38473846
if (localSettings.modelsFromConfig.size() > 0){
38483847
for (int n = 0; n < localSettings.modelsFromConfig.size(); n++){
38493848
if (localSettings.modelName == localSettings.modelsFromConfig[n].first) {

0 commit comments

Comments
 (0)