Skip to content

Commit

Permalink
Adding configuration option (.md config; persistence; dialog) to chan…
Browse files Browse the repository at this point in the history
…ge application font which resolves #1473 + finishing Wingman configuration, adding a few prompts and error reporting from OpenAI provider #1514
  • Loading branch information
dvorka committed Jan 28, 2024
1 parent 95bf29b commit c9221f4
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 32 deletions.
16 changes: 12 additions & 4 deletions app/src/qt/dialogs/configuration_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ ConfigurationDialog::AppTab::AppTab(QWidget *parent)
#endif
startupCombo->addItem(QString{START_TO_HOME_OUTLINE});

appFontSizeLabel = new QLabel(
tr("Application font size - 0 is system (<font color='#ff0000'>requires restart</font>)")+":", this);
appFontSizeSpin = new QSpinBox(this);
appFontSizeSpin->setMinimum(0);
appFontSizeSpin->setMaximum(68);

showToolbarCheck = new QCheckBox(tr("show toolbar"), this);
showToolbarCheck->setChecked(true);
uiExpertModeCheck = new QCheckBox(
Expand All @@ -149,6 +155,8 @@ ConfigurationDialog::AppTab::AppTab(QWidget *parent)
QVBoxLayout* appearanceLayout = new QVBoxLayout{this};
appearanceLayout->addWidget(themeLabel);
appearanceLayout->addWidget(themeCombo);
appearanceLayout->addWidget(appFontSizeLabel);
appearanceLayout->addWidget(appFontSizeSpin);
appearanceLayout->addWidget(menuLabel);
appearanceLayout->addWidget(nerdMenuCheck);
QGroupBox* appearanceGroup = new QGroupBox{tr("Appearance"), this};
Expand All @@ -172,6 +180,8 @@ ConfigurationDialog::AppTab::~AppTab()
{
delete themeLabel;
delete themeCombo;
delete appFontSizeLabel;
delete appFontSizeSpin;
delete startupLabel;
delete startupCombo;
delete showToolbarCheck;
Expand All @@ -188,6 +198,7 @@ void ConfigurationDialog::AppTab::refresh()
themeCombo->setCurrentIndex(i);
}
showToolbarCheck->setChecked(config.isUiShowToolbar());
appFontSizeSpin->setValue(config.getUiAppFontSize());
uiExpertModeCheck->setChecked(config.isUiExpertMode());
nerdMenuCheck->setChecked(config.isUiNerdTargetAudience());
}
Expand All @@ -197,6 +208,7 @@ void ConfigurationDialog::AppTab::save()
config.setStartupView(startupCombo->itemText(startupCombo->currentIndex()).toStdString());
config.setUiThemeName(themeCombo->itemText(themeCombo->currentIndex()).toStdString());
config.setUiShowToolbar(showToolbarCheck->isChecked());
config.setUiAppFontSize(appFontSizeSpin->value());
config.setUiExpertMode(uiExpertModeCheck->isChecked());
config.setUiNerdTargetAudience(nerdMenuCheck->isChecked());
}
Expand Down Expand Up @@ -702,8 +714,6 @@ ConfigurationDialog::WingmanTab::~WingmanTab()

void ConfigurationDialog::WingmanTab::refresh()
{
// TODO to be implemented - use App as inspiration

// refresh LLM providers combo
llmProvidersCombo->clear();
llmProvidersCombo->addItem(""); // disable Wingman
Expand All @@ -723,8 +733,6 @@ void ConfigurationDialog::WingmanTab::refresh()

void ConfigurationDialog::WingmanTab::save()
{
// TODO to be implemented - use App as inspiration

// get LLM provider enum value from llmProvidersCombo
WingmanLlmProviders llmProvider = static_cast<WingmanLlmProviders>(
llmProvidersCombo->itemData(llmProvidersCombo->currentIndex()).toInt());
Expand Down
3 changes: 3 additions & 0 deletions app/src/qt/dialogs/configuration_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class ConfigurationDialog::AppTab : public QWidget
QLabel* menuLabel;
QComboBox* themeCombo;

QLabel* appFontSizeLabel;
QSpinBox* appFontSizeSpin;

QLabel* startupLabel;
QComboBox* startupCombo;

Expand Down
3 changes: 2 additions & 1 deletion app/src/qt/dialogs/wingman_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ WingmanDialog::WingmanDialog(QWidget* parent)

// assembly
QHBoxLayout* buttonLayout = new QHBoxLayout{};
buttonLayout->addStretch(1);
//buttonLayout->addStretch(1);
buttonLayout->addWidget(closeButton);
buttonLayout->addWidget(toggleContextButton);
buttonLayout->addWidget(togglePromptSourceButton);
buttonLayout->addStretch(1);
buttonLayout->addWidget(copyButton);
buttonLayout->addWidget(askButton);
buttonLayout->addStretch();
Expand Down
19 changes: 14 additions & 5 deletions app/src/qt/main_window_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2245,11 +2245,20 @@ void MainWindowPresenter::slotRunWingmanFromDialog()
};

// PUSH answer to the chat dialog
this->wingmanDialog->appendAnswerToChat(
commandWingmanChat.answerHtml,
answerDescriptor,
this->wingmanDialog->getContextType()
);
if(WingmanStatusCode::WINGMAN_STATUS_CODE_ERROR == commandWingmanChat.status) {
this->wingmanDialog->appendAnswerToChat(
commandWingmanChat.errorMessage,
answerDescriptor,
this->wingmanDialog->getContextType(),
true
);
} else {
this->wingmanDialog->appendAnswerToChat(
commandWingmanChat.answerHtml,
answerDescriptor,
this->wingmanDialog->getContextType()
);
}
}

void MainWindowPresenter::doActionOutlineOrNoteNew()
Expand Down
26 changes: 21 additions & 5 deletions app/src/qt/mindforger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,27 @@ int main(int argc, char* argv[])
// mdConfigRepresentation->save(config);

// set application font family and size
// TODO QFont font("Arial", 25);
//mindforgerApplication.setFont(font);
MF_DEBUG("Application font family: " << mindforgerApplication.font().family().toStdString() << endl);
MF_DEBUG("Application font pixel size: " << mindforgerApplication.font().pixelSize() << endl);
MF_DEBUG("Application font point size: " << mindforgerApplication.font().pointSize() << endl);
// QFont font("Arial", 25);
// mindforgerApplication.setFont(font);
MF_DEBUG(
"Qt boot MindForger application font:" << endl <<
" family: " << mindforgerApplication.font().family().toStdString() << endl <<
" pixel size: " << mindforgerApplication.font().pixelSize() << endl <<
" point size: " << mindforgerApplication.font().pointSize() << endl);
if(config.getUiAppFontSize()) {
MF_DEBUG("Setting application font size to: " << config.getUiAppFontSize() << endl);
QFont font(
mindforgerApplication.font().family(),
config.getUiAppFontSize()
);
mindforgerApplication.setFont(font);

MF_DEBUG(
"AFTER MindForger application font reconfiguration:" << endl <<
" family: " << mindforgerApplication.font().family().toStdString() << endl <<
" pixel size: " << mindforgerApplication.font().pixelSize() << endl <<
" point size: " << mindforgerApplication.font().pointSize() << endl);
}

// initialize and start UI
m8r::MainWindowView mainWindowView(lookAndFeels);
Expand Down
11 changes: 9 additions & 2 deletions lib/src/config/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Configuration::Configuration()
autolinking{DEFAULT_AUTOLINKING},
autolinkingColonSplit{},
autolinkingCaseInsensitive{},
wingmanProvider{WingmanLlmProviders::WINGMAN_PROVIDER_OPENAI},
wingmanProvider{WingmanLlmProviders::WINGMAN_PROVIDER_NONE},
wingmanApiKey{},
wingmanLlmModel{"gpt-3.5-turbo"},
md2HtmlOptions{},
Expand Down Expand Up @@ -440,7 +440,7 @@ bool Configuration::initWingmanOpenAi() {
bool Configuration::initWingman()
{
MF_DEBUG(
" Configuration::initWingman():" << endl <<
" BEFORE Configuration::initWingman():" << endl <<
" LLM provider: " << wingmanProvider << endl <<
" OpenAI API key env var name: " << ENV_VAR_OPENAI_API_KEY << endl <<
" Wingman provider API key : " << wingmanApiKey << endl
Expand Down Expand Up @@ -475,6 +475,13 @@ bool Configuration::initWingman()
wingmanLlmModel.clear();
}

MF_DEBUG(
" BEFORE Configuration::initWingman():" << endl <<
" LLM provider: " << wingmanProvider << endl <<
" OpenAI API key env var name: " << ENV_VAR_OPENAI_API_KEY << endl <<
" Wingman provider API key : " << wingmanApiKey << endl
);

return initialized;
}

Expand Down
15 changes: 13 additions & 2 deletions lib/src/config/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class Configuration {
static const std::string DEFAULT_UI_THEME_NAME;
static constexpr const bool DEFAULT_UI_SHOW_TOOLBAR = true;
static constexpr const bool DEFAULT_UI_EXPERT_MODE = false;
static constexpr const int DEFAULT_UI_APP_FONT_SIZE = 0;
static constexpr const bool DEFAULT_UI_LIVE_NOTE_PREVIEW = true;
static constexpr const bool DEFAULT_UI_NERD_MENU = false;
static const std::string DEFAULT_UI_HTML_CSS_THEME;
Expand Down Expand Up @@ -369,6 +370,7 @@ class Configuration {
bool uiFullOPreview;
bool uiShowToolbar;
bool uiExpertMode;
int uiAppFontSize;
bool uiDistractionFreeMode; // fullscreen, no split, hidden toolbar + menu
bool uiHoistedMode; // no split
bool uiLiveNotePreview;
Expand Down Expand Up @@ -492,6 +494,11 @@ class Configuration {
*/
void setWingmanLlmProvider(WingmanLlmProviders provider);
WingmanLlmProviders getWingmanLlmProvider() const { return wingmanProvider; }
std::string getWingmanLlmProviderAsString(WingmanLlmProviders provider) const {
if(provider==WINGMAN_PROVIDER_MOCK) return "mock";
else if(provider==WINGMAN_PROVIDER_OPENAI) return "openai";
else return "none";
}
#ifdef MF_WIP
bool canWingmanMock() { return true; }
#else
Expand Down Expand Up @@ -658,7 +665,12 @@ class Configuration {
bool isUiShowToolbar() const { return uiShowToolbar; }
void setUiShowToolbar(bool showToolbar){ this->uiShowToolbar = showToolbar; }
bool isUiExpertMode() const { return uiExpertMode; }
void setUiExpertMode(bool uiExpertMode){ this->uiExpertMode= uiExpertMode; }
void setUiExpertMode(bool uiExpertMode){ this->uiExpertMode = uiExpertMode; }
int getUiAppFontSize() const { return uiAppFontSize; }
void setUiAppFontSize(int appFontSize){
MF_DEBUG("Configuration::setUiAppFontSize: " << appFontSize << std::endl);
this->uiAppFontSize = appFontSize;
}
bool isUiDistractionFreeMode() const { return uiDistractionFreeMode; }
void setUiDistractionFreeMode(bool distractionFreeMode){ this->uiDistractionFreeMode = distractionFreeMode; }
bool isUiHoistedMode() const { return uiHoistedMode; }
Expand All @@ -671,7 +683,6 @@ class Configuration {
void setUiOsTableSortOrder(const bool ascending) { this->uiOsTableSortOrder = ascending; }
bool isUiDoubleClickNoteViewToEdit() const { return this->uiDoubleClickNoteViewToEdit; }
void setUiDoubleClickNoteViewToEdit(bool enable) { this->uiDoubleClickNoteViewToEdit = enable; }

};

} // namespace
Expand Down
12 changes: 10 additions & 2 deletions lib/src/mind/ai/llm/openai_wingman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ OpenAiWingman::OpenAiWingman(
apiKey{apiKey},
llmModel{llmModel}
{
MF_DEBUG("OpenAiWingman::OpenAiWingman() apiKey: " << apiKey << endl);
}

OpenAiWingman::~OpenAiWingman()
Expand Down Expand Up @@ -221,8 +222,15 @@ void OpenAiWingman::curlGet(CommandWingmanChat& command) {
}
} else {
command.status = m8r::WingmanStatusCode::WINGMAN_STATUS_CODE_ERROR;
command.errorMessage.assign(
"No choices in the OpenAI API HTTP response");
if(
httpResponseJSon.contains("error")
&& httpResponseJSon["error"].contains("message")
) {
httpResponseJSon["error"]["message"].get_to(command.errorMessage);
} else {
command.errorMessage.assign(
"No choices in the OpenAI API HTTP response");
}
}
} else {
command.status = m8r::WingmanStatusCode::WINGMAN_STATUS_CODE_ERROR;
Expand Down
30 changes: 20 additions & 10 deletions lib/src/mind/ai/llm/wingman.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ constexpr const auto PROMPT_FIND_LOCATIONS = "Find locations in: #NAME. #TEXT";
constexpr const auto PROMPT_FIND_ORGS = "Find organizations in: #NAME. #TEXT";
constexpr const auto PROMPT_CHAT = "Chat with the context.";

constexpr const auto PROMPT_SHORTEN = "Shorten #TEXT";
constexpr const auto PROMPT_EXPLAIN_LIKE_5 = "Explain #NAME like I'm 5.";
constexpr const auto PROMPT_SHORTEN = "Shorten: #TEXT";
constexpr const auto PROMPT_EXPLAIN_LIKE_5 = "Explain like I'm 5: #TEXT";
constexpr const auto PROMPT_FIX_GRAMMAR = "Fix grammar in: #TEXT";
constexpr const auto PROMPT_FIND_GRAMMAR = "Find grammar errors in: #TEXT";
constexpr const auto PROMPT_TRANSLATE_EN = "Translate to English: #TEXT";
constexpr const auto PROMPT_REWRITE_FORMALLY = "Rewrite formally: #TEXT";
constexpr const auto PROMPT_REWRITE_INFORMALLY = "Rewrite informally: #TEXT";
constexpr const auto PROMPT_REWRITE_KAFKA = "Rewrite in Kafka style: #TEXT";

constexpr const auto PROMPT_COMPLETE_TEXT = "Complete the text: #TEXT";
constexpr const auto PROMPT_REWRITE_ACADEMIA = "Rewrite in academic style: #TEXT";
constexpr const auto PROMPT_REWRITE_SLANG = "Rewrite in a slang style: #TEXT";
constexpr const auto PROMPT_SYNONYM = "Give synonym to: #TEXT";
constexpr const auto PROMPT_ANTONYM = "Give antonym to: #TEXT";
constexpr const auto PROMPT_COMPLETE_TEXT = "Complete work-in-progress text: #TEXT";

// other UCs:
// - NER UCs
Expand Down Expand Up @@ -91,6 +94,8 @@ class Wingman

std::vector<std::string> outlinePrompts = {
PROMPT_SUMMARIZE,
PROMPT_TRANSLATE_EN,
PROMPT_FIND_GRAMMAR,
PROMPT_GENERATE_TAGS,
PROMPT_FIND_PERSONS,
PROMPT_FIND_LOCATIONS,
Expand All @@ -101,23 +106,28 @@ class Wingman
std::vector<std::string> notePrompts = {
PROMPT_SUMMARIZE,
PROMPT_SHORTEN,
PROMPT_FIND_GRAMMAR,
PROMPT_EXPLAIN_LIKE_5,
PROMPT_TRANSLATE_EN,
PROMPT_GENERATE_TAGS,
PROMPT_FIX_GRAMMAR,
PROMPT_REWRITE_FORMALLY,
PROMPT_REWRITE_INFORMALLY,
PROMPT_REWRITE_KAFKA,
PROMPT_REWRITE_SLANG,
// PROMPT_CHAT,
};

std::vector<std::string> textPrompts = {
PROMPT_COMPLETE_TEXT,
PROMPT_EXPLAIN_LIKE_5,
PROMPT_FIX_GRAMMAR,
PROMPT_FIND_GRAMMAR,
PROMPT_TRANSLATE_EN,
PROMPT_GENERATE_TAGS,
PROMPT_REWRITE_FORMALLY,
PROMPT_REWRITE_INFORMALLY,
PROMPT_REWRITE_KAFKA,
PROMPT_REWRITE_ACADEMIA,
PROMPT_REWRITE_SLANG,
PROMPT_SYNONYM,
PROMPT_ANTONYM,
};

public:
Expand Down
3 changes: 3 additions & 0 deletions lib/src/mind/mind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ Mind::Mind(Configuration &configuration)
{
ai = new Ai{memory, *this};

// TODO BEGIN: code before Wingman config persisted
config.setWingmanLlmProvider(WingmanLlmProviders::WINGMAN_PROVIDER_OPENAI);
// TODO END: code before Wingman config persisted
initWingman();

deleteWatermark = 0;
Expand Down
Loading

0 comments on commit c9221f4

Please sign in to comment.