From f8b962d50a51d5ed2e83ffa57342bf895eae1e63 Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Sun, 16 Apr 2023 13:56:18 -0400 Subject: [PATCH] More conservative default params and trim leading whitespace from response. --- llm.cpp | 10 +++++++++- main.qml | 27 ++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/llm.cpp b/llm.cpp index 54f6bd22..09ab4954 100644 --- a/llm.cpp +++ b/llm.cpp @@ -80,9 +80,17 @@ void LLMObject::resetContext() s_ctx = LLModel::PromptContext(); } +std::string remove_leading_whitespace(const std::string& input) { + auto first_non_whitespace = std::find_if(input.begin(), input.end(), [](unsigned char c) { + return !std::isspace(c) || c == '\n'; + }); + + return std::string(first_non_whitespace, input.end()); +} + QString LLMObject::response() const { - return QString::fromStdString(m_response); + return QString::fromStdString(remove_leading_whitespace(m_response)); } QString LLMObject::modelName() const diff --git a/main.qml b/main.qml index 8975fa0e..2edba61d 100644 --- a/main.qml +++ b/main.qml @@ -54,11 +54,11 @@ Window { title: qsTr("Settings") height: 600 width: 600 - property real temperature: 0.9 - property real topP: 0.9 - property int topK: 40 - property int maxLength: 4096 - property int promptBatchSize: 9 + property real defaultTemperature: 0.7 + property real defaultTopP: 0.95 + property int defaultTopK: 40 + property int defaultMaxLength: 4096 + property int defaultPromptBatchSize: 9 property string defaultPromptTemplate: "The prompt below is a question to answer, a task to complete, or a conversation to respond to; decide which and write an appropriate response. ### Prompt: @@ -66,18 +66,23 @@ Window { ### Response:\n" property string promptTemplate: "" + property real temperature: 0.0 + property real topP: 0.0 + property int topK: 0 + property int maxLength: 0 + property int promptBatchSize: 0 function restoreDefaults() { - temperature = 0.9; - topP = 0.9; - topK = 40; - maxLength = 4096; - promptBatchSize = 9; + temperature = defaultTemperature; + topP = defaultTopP; + topK = defaultTopK; + maxLength = defaultMaxLength; + promptBatchSize = defaultPromptBatchSize; promptTemplate = defaultPromptTemplate; } Component.onCompleted: { - promptTemplate = defaultPromptTemplate; + restoreDefaults(); } GridLayout {