Skip to content

Commit

Permalink
Wingman MOCK done.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvorka committed Jan 13, 2024
1 parent 81eeb94 commit e688f45
Show file tree
Hide file tree
Showing 16 changed files with 420 additions and 151 deletions.
91 changes: 51 additions & 40 deletions app/src/qt/dialogs/chat_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace m8r {

using namespace std;

const string COLOR_PROMPT_GREEN{"#00bb00"};
const string COLOR_PROMPT_BLUE{"#00aaaa"};

ChatDialog::ChatDialog(QWidget* parent)
: QDialog(parent)
{
Expand Down Expand Up @@ -54,7 +57,7 @@ ChatDialog::ChatDialog(QWidget* parent)
chatWindow = new QTextEdit(this);
chatWindow->setReadOnly(true);
chatWindow->clear();
chatWindow->insertHtml(QString::fromStdString(getPrompt()));
chatWindow->insertHtml(QString::fromStdString(getTerminalPrompt()));

QVBoxLayout* layout = new QVBoxLayout{this};
layout->addWidget(chatWindow);
Expand All @@ -70,15 +73,20 @@ ChatDialog::~ChatDialog()

void ChatDialog::show()
{
// > Summarize. [green]
// 🤖 Lorem ipsum dolor sit amet, [gray]
// Notebook/<name> OpenAI chatGPT3.5 [blue, yellow]
// $ Summarize. [green]
//
// Lorem ipsum dolor sit amet, [gray]
// consectetur adipiscing elit.
//
// Explain like I'm 5: NLP.
// 🤖 Lorem ipsum dolor sit amet,
// ~/notebook/<name> OpenAI chatGPT3.5
// $ Explain 'NLP' like I'm 5.
//
// Lorem ipsum dolor sit amet,
//
// >
// ^ cursor
// ~/notebook/<name> OpenAI chatGPT3.5
// $
// ^ cursor

cmdEdit->clear();
cmdEdit->setFocus();
Expand All @@ -87,14 +95,27 @@ void ChatDialog::show()
QDialog::show();
}

string ChatDialog::getPrompt(bool error)
string ChatDialog::getTerminalPrompt(bool error)
{
string prompt{"<font color='#0000ff'>" + getCwd() + "</font>"};
prompt.append("<br/><font color='");
// TODO
string thing{"notebook"};
string thingName{"My notebook"};
string wingmanModel{"OpenAI gpt-3"};

string prompt{
"<hr/>"
"<font color='" + COLOR_PROMPT_BLUE + "'>@" + thing + "</font> " +
"<font color='" + COLOR_PROMPT_GREEN + "'><b>" + thingName + "</b></font>"
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
"<font color='" + COLOR_PROMPT_BLUE + "'>" + wingmanModel + "</font>"
"<br/>"
};

prompt.append("<font color='");
if(error) {
prompt.append("#ff0000");
} else {
prompt.append("#00ff00");
prompt.append(COLOR_PROMPT_GREEN);
}
prompt.append("'>&gt;</font> ");
return prompt;
Expand All @@ -104,17 +125,26 @@ void ChatDialog::insertPrompt(const std::string& prompt)
{
chatWindow->insertHtml(
QString::fromStdString(
"<font color='#00bb00'>"
"&gt; " + prompt +
"<font color='"+COLOR_PROMPT_GREEN+"'>" +
prompt +
"</font>"
"<br/><br/>"
));
chatWindow->insertHtml(QString::fromStdString("<br/><br/>"));
chatWindow->moveCursor(QTextCursor::End);
chatWindow->ensureCursorVisible();
}

void ChatDialog::insertOutput(const std::string& output)
void ChatDialog::insertOutput(const std::string& output, bool error)
{
chatWindow->insertHtml(QString::fromStdString("🤖 " + output));
chatWindow->insertHtml(QString::fromStdString("<br/><br/>"));
chatWindow->insertHtml(
QString::fromStdString(
"<br/>" +
output +
"<br/>" +
getTerminalPrompt(error)
));
chatWindow->moveCursor(QTextCursor::End);
chatWindow->ensureCursorVisible();
}

void ChatDialog::runCommand()
Expand All @@ -125,7 +155,7 @@ void ChatDialog::runCommand()
|| cmdEdit->text() == QString::fromStdString("cls")
) {
chatWindow->clear();
chatWindow->insertHtml(QString::fromStdString(getPrompt()));
chatWindow->insertHtml(QString::fromStdString(getTerminalPrompt()));
} else if(cmdEdit->text() == QString::fromStdString("exit")
|| cmdEdit->text() == QString::fromStdString("quit")
|| cmdEdit->text() == QString::fromStdString("bye")
Expand All @@ -151,36 +181,17 @@ void ChatDialog::runCommand()
// run prompt
MF_DEBUG("Running prompt: '" << cmd << "'" << endl);
int statusCode{0};
string cmdStdOut{};
string cmdStdOut{"Foo result Lorem ipsum dolor sit amet, consectetur adipiscing elit."};

// TODO run prompt
// TODO run prompt
// TODO run prompt

MF_DEBUG("Chat command finished with status: " << statusCode << endl);
chatWindow->insertHtml(QString::fromStdString("<br/>"));

if(cmdStdOut.size()) {
replaceAll("\n", "<br/>", cmdStdOut);
chatWindow->insertHtml(
QString::fromStdString("🤖 " + cmdStdOut + "<br/>")
);
// replaceAll("\n", "<br/>", cmdStdOut);
this->insertOutput(cmdStdOut, statusCode!=0?true:false);
}

if(statusCode) {
cerr << "Chat command failed with status: " << statusCode << endl;
chatWindow->insertHtml(
QString::fromStdString(getPrompt(true))
);
} else {
chatWindow->insertHtml(
QString::fromStdString(getPrompt())
);
}

// scroll down by moving cursor to the end AND ensuring it's visible
chatWindow->moveCursor(QTextCursor::End);
chatWindow->ensureCursorVisible();
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/qt/dialogs/chat_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ class ChatDialog : public QDialog
~ChatDialog();

void insertPrompt(const std::string& prompt);
void insertOutput(const std::string& output);
void insertOutput(const std::string& output, bool error=false);

void show();

private:
void runCommand();
std::string getPrompt(bool error=false);
std::string getTerminalPrompt(bool error=false);
};

}
Expand Down
104 changes: 46 additions & 58 deletions app/src/qt/dialogs/wingman_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,33 @@ namespace m8r {

using namespace std;

const vector<QString> WingmanDialog::outlinePrompts(
{
QString{"Summarize."},
QString{"Generate tags from the text."},
QString{"Find persons."},
QString{"Find locations."},
QString{"Find organizations."},
QString{"Chat with the content."},
WingmanDialog::WingmanDialog(
const vector<string>& predefinedOPrompts,
const vector<string>& predefinedNPrompts,
const vector<string>& predefinedTPrompts,
QWidget* parent
):
context{},
QDialog(parent)
{
for(string prompt:predefinedOPrompts) {
outlinePrompts.push_back(QString::fromStdString(prompt));
}
);
const vector<QString> WingmanDialog::notePrompts(
{
QString{"Summarize."},
QString{"Shorten."},
QString{"Explain #NAME like I'm 5."},
QString{"Generate tags."},
QString{"Fix grammar."},
QString{"Rewrite formally."},
QString{"Rewrite informally."},
QString{"Rewrite to be funny."},
QString{"Chat with the content."},
// other UCs:
// - NER UCs
// - simplify
// - beautify
// - translate
// - fix spelling
// - fix style
// - create plan ...
for(string prompt:predefinedNPrompts) {
notePrompts.push_back(QString::fromStdString(prompt));
}
);
const vector<QString> WingmanDialog::textPrompts(
{
QString{"Complete the text."},
QString{"Complete the last text line."},
QString{"Explain like I'm 5."},
QString{"Fix grammar."},
QString{"Generate tags."},
QString{"Rewrite formally."},
QString{"Rewrite informally."},
QString{"Rewrite to Kafka style."},
for(string prompt:predefinedTPrompts) {
textPrompts.push_back(QString::fromStdString(prompt));
}
);

WingmanDialog::WingmanDialog(QWidget* parent)
: QDialog(parent)
{
// UI
setWindowTitle(tr("Wingman"));

preludeLabel = new QLabel{
tr(
"Wingman can run a predefined or custom prompt."
"Wingman can run a predefined or custom prompt"
" "
"with the selected context."
"<br>"
),
parent
Expand All @@ -90,8 +64,10 @@ WingmanDialog::WingmanDialog(QWidget* parent)
predefinedPromptsCombo->addItem(toolName);
}

promptLabel = new QLabel{tr("Your:"), parent};
promptEdit = new QLineEdit{parent};
promptLabel = new QLabel{
tr("Your (overrides Predefined, use #NAME or #TEXT to include context):"),
parent};
promptEdit = new QTextEdit{parent};
promptEdit->setToolTip(
tr("Type in your prompt like: 'Translate the following text to Spanish: #CONTENT."));

Expand All @@ -117,17 +93,12 @@ WingmanDialog::WingmanDialog(QWidget* parent)
contextEdit = new QLineEdit{parent};
contextEdit->setReadOnly(true);

postmortemLabel = new QLabel{
tr("Use #NAME or #TEXT to include it to your prompt."),
parent};

contentLayout->addWidget(contextTypeLabel);
contentLayout->addWidget(contextTypeEdit);
contentLayout->addWidget(contextNameLabel);
contentLayout->addWidget(contextNameEdit);
contentLayout->addWidget(contextLabel);
contentLayout->addWidget(contextEdit);
contentLayout->addWidget(postmortemLabel);
contentLayout->addWidget(contextTypeLabel);
contentLayout->addWidget(contextTypeEdit);
contentGroup->setLayout(contentLayout);

// IMPROVE disable/enable find button if text/path is valid: freedom vs validation
Expand Down Expand Up @@ -176,31 +147,48 @@ WingmanDialog::~WingmanDialog()
delete contextLabel;
delete contextEdit;

delete postmortemLabel;

delete runButton;
delete closeButton;
}

void WingmanDialog::clear()
{
this->context.clear();

this->promptEdit->clear();
this->contextNameEdit->clear();
this->contextEdit->clear();
}

void WingmanDialog::initForMode(WingmanDialogModes mode)
{
this->mode=mode;

switch(mode) {
case WingmanDialogModes::WINGMAN_DIALOG_MODE_OUTLINE:
contextTypeEdit->setText(tr("outline"));
contextEdit->setText(tr("<Notebook document>"));
contextEdit->setText(tr("<Notebook text>"));
break;
case WingmanDialogModes::WINGMAN_DIALOG_MODE_NOTE:
contextTypeEdit->setText(tr("note"));
contextEdit->setText(tr("<Note description>"));
contextEdit->setText(tr("<Note text>"));
break;
case WingmanDialogModes::WINGMAN_DIALOG_MODE_TEXT:
contextEdit->setText(tr("<selected / current text>"));
contextNameEdit->clear();
contextEdit->clear();
break;
}
}

void WingmanDialog::setContextText(QString context) {
this->context=context;
this->contextEdit->setText(context.mid(0, 50).append("..."));
}

QString WingmanDialog::getContextText() const {
return context;
}

void WingmanDialog::show()
{
QDialog::show();
Expand Down
Loading

0 comments on commit e688f45

Please sign in to comment.