Skip to content

Commit e688f45

Browse files
committed
Wingman MOCK done.
1 parent 81eeb94 commit e688f45

16 files changed

+420
-151
lines changed

app/src/qt/dialogs/chat_dialog.cpp

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ namespace m8r {
2222

2323
using namespace std;
2424

25+
const string COLOR_PROMPT_GREEN{"#00bb00"};
26+
const string COLOR_PROMPT_BLUE{"#00aaaa"};
27+
2528
ChatDialog::ChatDialog(QWidget* parent)
2629
: QDialog(parent)
2730
{
@@ -54,7 +57,7 @@ ChatDialog::ChatDialog(QWidget* parent)
5457
chatWindow = new QTextEdit(this);
5558
chatWindow->setReadOnly(true);
5659
chatWindow->clear();
57-
chatWindow->insertHtml(QString::fromStdString(getPrompt()));
60+
chatWindow->insertHtml(QString::fromStdString(getTerminalPrompt()));
5861

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

7174
void ChatDialog::show()
7275
{
73-
// > Summarize. [green]
74-
// 🤖 Lorem ipsum dolor sit amet, [gray]
76+
// Notebook/<name> OpenAI chatGPT3.5 [blue, yellow]
77+
// $ Summarize. [green]
78+
//
79+
// Lorem ipsum dolor sit amet, [gray]
7580
// consectetur adipiscing elit.
7681
//
77-
// Explain like I'm 5: NLP.
78-
// 🤖 Lorem ipsum dolor sit amet,
82+
// ~/notebook/<name> OpenAI chatGPT3.5
83+
// $ Explain 'NLP' like I'm 5.
84+
//
85+
// Lorem ipsum dolor sit amet,
7986
//
80-
// >
81-
// ^ cursor
87+
// ~/notebook/<name> OpenAI chatGPT3.5
88+
// $
89+
// ^ cursor
8290

8391
cmdEdit->clear();
8492
cmdEdit->setFocus();
@@ -87,14 +95,27 @@ void ChatDialog::show()
8795
QDialog::show();
8896
}
8997

90-
string ChatDialog::getPrompt(bool error)
98+
string ChatDialog::getTerminalPrompt(bool error)
9199
{
92-
string prompt{"<font color='#0000ff'>" + getCwd() + "</font>"};
93-
prompt.append("<br/><font color='");
100+
// TODO
101+
string thing{"notebook"};
102+
string thingName{"My notebook"};
103+
string wingmanModel{"OpenAI gpt-3"};
104+
105+
string prompt{
106+
"<hr/>"
107+
"<font color='" + COLOR_PROMPT_BLUE + "'>@" + thing + "</font> " +
108+
"<font color='" + COLOR_PROMPT_GREEN + "'><b>" + thingName + "</b></font>"
109+
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
110+
"<font color='" + COLOR_PROMPT_BLUE + "'>" + wingmanModel + "</font>"
111+
"<br/>"
112+
};
113+
114+
prompt.append("<font color='");
94115
if(error) {
95116
prompt.append("#ff0000");
96117
} else {
97-
prompt.append("#00ff00");
118+
prompt.append(COLOR_PROMPT_GREEN);
98119
}
99120
prompt.append("'>&gt;</font> ");
100121
return prompt;
@@ -104,17 +125,26 @@ void ChatDialog::insertPrompt(const std::string& prompt)
104125
{
105126
chatWindow->insertHtml(
106127
QString::fromStdString(
107-
"<font color='#00bb00'>"
108-
"&gt; " + prompt +
128+
"<font color='"+COLOR_PROMPT_GREEN+"'>" +
129+
prompt +
109130
"</font>"
131+
"<br/><br/>"
110132
));
111-
chatWindow->insertHtml(QString::fromStdString("<br/><br/>"));
133+
chatWindow->moveCursor(QTextCursor::End);
134+
chatWindow->ensureCursorVisible();
112135
}
113136

114-
void ChatDialog::insertOutput(const std::string& output)
137+
void ChatDialog::insertOutput(const std::string& output, bool error)
115138
{
116-
chatWindow->insertHtml(QString::fromStdString("🤖 " + output));
117-
chatWindow->insertHtml(QString::fromStdString("<br/><br/>"));
139+
chatWindow->insertHtml(
140+
QString::fromStdString(
141+
"<br/>" +
142+
output +
143+
"<br/>" +
144+
getTerminalPrompt(error)
145+
));
146+
chatWindow->moveCursor(QTextCursor::End);
147+
chatWindow->ensureCursorVisible();
118148
}
119149

120150
void ChatDialog::runCommand()
@@ -125,7 +155,7 @@ void ChatDialog::runCommand()
125155
|| cmdEdit->text() == QString::fromStdString("cls")
126156
) {
127157
chatWindow->clear();
128-
chatWindow->insertHtml(QString::fromStdString(getPrompt()));
158+
chatWindow->insertHtml(QString::fromStdString(getTerminalPrompt()));
129159
} else if(cmdEdit->text() == QString::fromStdString("exit")
130160
|| cmdEdit->text() == QString::fromStdString("quit")
131161
|| cmdEdit->text() == QString::fromStdString("bye")
@@ -151,36 +181,17 @@ void ChatDialog::runCommand()
151181
// run prompt
152182
MF_DEBUG("Running prompt: '" << cmd << "'" << endl);
153183
int statusCode{0};
154-
string cmdStdOut{};
184+
string cmdStdOut{"Foo result Lorem ipsum dolor sit amet, consectetur adipiscing elit."};
155185

156186
// TODO run prompt
157187
// TODO run prompt
158188
// TODO run prompt
159189

160190
MF_DEBUG("Chat command finished with status: " << statusCode << endl);
161-
chatWindow->insertHtml(QString::fromStdString("<br/>"));
162-
163191
if(cmdStdOut.size()) {
164-
replaceAll("\n", "<br/>", cmdStdOut);
165-
chatWindow->insertHtml(
166-
QString::fromStdString("🤖 " + cmdStdOut + "<br/>")
167-
);
192+
// replaceAll("\n", "<br/>", cmdStdOut);
193+
this->insertOutput(cmdStdOut, statusCode!=0?true:false);
168194
}
169-
170-
if(statusCode) {
171-
cerr << "Chat command failed with status: " << statusCode << endl;
172-
chatWindow->insertHtml(
173-
QString::fromStdString(getPrompt(true))
174-
);
175-
} else {
176-
chatWindow->insertHtml(
177-
QString::fromStdString(getPrompt())
178-
);
179-
}
180-
181-
// scroll down by moving cursor to the end AND ensuring it's visible
182-
chatWindow->moveCursor(QTextCursor::End);
183-
chatWindow->ensureCursorVisible();
184195
}
185196
}
186197

app/src/qt/dialogs/chat_dialog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ class ChatDialog : public QDialog
7474
~ChatDialog();
7575

7676
void insertPrompt(const std::string& prompt);
77-
void insertOutput(const std::string& output);
77+
void insertOutput(const std::string& output, bool error=false);
7878

7979
void show();
8080

8181
private:
8282
void runCommand();
83-
std::string getPrompt(bool error=false);
83+
std::string getTerminalPrompt(bool error=false);
8484
};
8585

8686
}

app/src/qt/dialogs/wingman_dialog.cpp

Lines changed: 46 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,59 +22,33 @@ namespace m8r {
2222

2323
using namespace std;
2424

25-
const vector<QString> WingmanDialog::outlinePrompts(
26-
{
27-
QString{"Summarize."},
28-
QString{"Generate tags from the text."},
29-
QString{"Find persons."},
30-
QString{"Find locations."},
31-
QString{"Find organizations."},
32-
QString{"Chat with the content."},
25+
WingmanDialog::WingmanDialog(
26+
const vector<string>& predefinedOPrompts,
27+
const vector<string>& predefinedNPrompts,
28+
const vector<string>& predefinedTPrompts,
29+
QWidget* parent
30+
):
31+
context{},
32+
QDialog(parent)
33+
{
34+
for(string prompt:predefinedOPrompts) {
35+
outlinePrompts.push_back(QString::fromStdString(prompt));
3336
}
34-
);
35-
const vector<QString> WingmanDialog::notePrompts(
36-
{
37-
QString{"Summarize."},
38-
QString{"Shorten."},
39-
QString{"Explain #NAME like I'm 5."},
40-
QString{"Generate tags."},
41-
QString{"Fix grammar."},
42-
QString{"Rewrite formally."},
43-
QString{"Rewrite informally."},
44-
QString{"Rewrite to be funny."},
45-
QString{"Chat with the content."},
46-
// other UCs:
47-
// - NER UCs
48-
// - simplify
49-
// - beautify
50-
// - translate
51-
// - fix spelling
52-
// - fix style
53-
// - create plan ...
37+
for(string prompt:predefinedNPrompts) {
38+
notePrompts.push_back(QString::fromStdString(prompt));
5439
}
55-
);
56-
const vector<QString> WingmanDialog::textPrompts(
57-
{
58-
QString{"Complete the text."},
59-
QString{"Complete the last text line."},
60-
QString{"Explain like I'm 5."},
61-
QString{"Fix grammar."},
62-
QString{"Generate tags."},
63-
QString{"Rewrite formally."},
64-
QString{"Rewrite informally."},
65-
QString{"Rewrite to Kafka style."},
40+
for(string prompt:predefinedTPrompts) {
41+
textPrompts.push_back(QString::fromStdString(prompt));
6642
}
67-
);
6843

69-
WingmanDialog::WingmanDialog(QWidget* parent)
70-
: QDialog(parent)
71-
{
7244
// UI
7345
setWindowTitle(tr("Wingman"));
7446

7547
preludeLabel = new QLabel{
7648
tr(
77-
"Wingman can run a predefined or custom prompt."
49+
"Wingman can run a predefined or custom prompt"
50+
" "
51+
"with the selected context."
7852
"<br>"
7953
),
8054
parent
@@ -90,8 +64,10 @@ WingmanDialog::WingmanDialog(QWidget* parent)
9064
predefinedPromptsCombo->addItem(toolName);
9165
}
9266

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

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

120-
postmortemLabel = new QLabel{
121-
tr("Use #NAME or #TEXT to include it to your prompt."),
122-
parent};
123-
124-
contentLayout->addWidget(contextTypeLabel);
125-
contentLayout->addWidget(contextTypeEdit);
12696
contentLayout->addWidget(contextNameLabel);
12797
contentLayout->addWidget(contextNameEdit);
12898
contentLayout->addWidget(contextLabel);
12999
contentLayout->addWidget(contextEdit);
130-
contentLayout->addWidget(postmortemLabel);
100+
contentLayout->addWidget(contextTypeLabel);
101+
contentLayout->addWidget(contextTypeEdit);
131102
contentGroup->setLayout(contentLayout);
132103

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

179-
delete postmortemLabel;
180-
181150
delete runButton;
182151
delete closeButton;
183152
}
184153

154+
void WingmanDialog::clear()
155+
{
156+
this->context.clear();
157+
158+
this->promptEdit->clear();
159+
this->contextNameEdit->clear();
160+
this->contextEdit->clear();
161+
}
162+
185163
void WingmanDialog::initForMode(WingmanDialogModes mode)
186164
{
187165
this->mode=mode;
188166

189167
switch(mode) {
190168
case WingmanDialogModes::WINGMAN_DIALOG_MODE_OUTLINE:
191169
contextTypeEdit->setText(tr("outline"));
192-
contextEdit->setText(tr("<Notebook document>"));
170+
contextEdit->setText(tr("<Notebook text>"));
193171
break;
194172
case WingmanDialogModes::WINGMAN_DIALOG_MODE_NOTE:
195173
contextTypeEdit->setText(tr("note"));
196-
contextEdit->setText(tr("<Note description>"));
174+
contextEdit->setText(tr("<Note text>"));
197175
break;
198176
case WingmanDialogModes::WINGMAN_DIALOG_MODE_TEXT:
199-
contextEdit->setText(tr("<selected / current text>"));
177+
contextNameEdit->clear();
178+
contextEdit->clear();
200179
break;
201180
}
202181
}
203182

183+
void WingmanDialog::setContextText(QString context) {
184+
this->context=context;
185+
this->contextEdit->setText(context.mid(0, 50).append("..."));
186+
}
187+
188+
QString WingmanDialog::getContextText() const {
189+
return context;
190+
}
191+
204192
void WingmanDialog::show()
205193
{
206194
QDialog::show();

0 commit comments

Comments
 (0)