Skip to content

Commit

Permalink
Display AI model name in GenerateCommitMessageDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
soramimi committed Jun 16, 2024
1 parent 8d6b32c commit a000dc5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/ApplicationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ ApplicationSettings ApplicationSettings::loadSettings()
GetValue<QString>(s, "OPENAI_API_KEY") >> as.openai_api_key;
GetValue<QString>(s, "ANTHROPIC_API_KEY") >> as.anthropic_api_key;
GetValue<QString>(s, "GOOGLE_API_KEY") >> as.google_api_key;
GetValue<QString>(s, "AiModel") >> as.ai_model.model;
GetValue<QString>(s, "AiModel") >> as.ai_model.name;
s.endGroup();

if (as.ai_model.model.isEmpty()) {
if (as.ai_model.name.isEmpty()) {
as.ai_model = {"gpt-4o"};
}

Expand Down Expand Up @@ -183,7 +183,7 @@ void ApplicationSettings::saveSettings() const
SetValue<QString>(s, "OPENAI_API_KEY") << this->openai_api_key;
SetValue<QString>(s, "ANTHROPIC_API_KEY") << this->anthropic_api_key;
SetValue<QString>(s, "GOOGLE_API_KEY") << this->google_api_key;
SetValue<QString>(s, "AiModel") << this->ai_model.model;
SetValue<QString>(s, "AiModel") << this->ai_model.name;
s.endGroup();

if (0) { // ここでは保存しない
Expand Down
2 changes: 1 addition & 1 deletion src/CommitDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void CommitDialog::on_checkbox_amend_stateChanged(int state)

void CommitDialog::on_pushButton_generate_with_ai_clicked()
{
GenerateCommitMessageDialog dlg(this);
GenerateCommitMessageDialog dlg(this, global->appsettings.ai_model.name);
dlg.show();
dlg.generate();
if (dlg.exec() == QDialog::Accepted) {
Expand Down
6 changes: 3 additions & 3 deletions src/CommitMessageGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ std::string CommitMessageGenerator::generatePromptJSON(GenerativeAI::Model const
{"role": "system", "content": "You are a experienced engineer."},
{"role": "user", "content": "%s"}]
})---";
json = strformat(json)(model.model.toStdString())(encode_json_string(prompt));
json = strformat(json)(model.name.toStdString())(encode_json_string(prompt));

} else if (type == GenerativeAI::CLAUDE) {

Expand All @@ -343,7 +343,7 @@ std::string CommitMessageGenerator::generatePromptJSON(GenerativeAI::Model const
"max_tokens": 100,
"temperature": 0.7
})---";
json = strformat(json)(model.model.toStdString())(encode_json_string(prompt));
json = strformat(json)(model.name.toStdString())(encode_json_string(prompt));

} else if (type == GenerativeAI::GEMINI) {

Expand Down Expand Up @@ -388,7 +388,7 @@ GeneratedCommitMessage CommitMessageGenerator::generate(GitPtr g)
}

GenerativeAI::Model model = global->appsettings.ai_model;
if (model.model.isEmpty()) {
if (model.name.isEmpty()) {
return GeneratedCommitMessage::Error("error", "AI model is not set.");
}

Expand Down
3 changes: 2 additions & 1 deletion src/GenerateCommitMessageDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ struct GenerateCommitMessageDialog::Private {
CommitMessageGenerator gen;
};

GenerateCommitMessageDialog::GenerateCommitMessageDialog(QWidget *parent)
GenerateCommitMessageDialog::GenerateCommitMessageDialog(QWidget *parent, QString const &model_name)
: QDialog(parent)
, ui(new Ui::GenerateCommitMessageDialog)
, m(new Private)
{
ui->setupUi(this);
ui->label->setText(model_name);

connect(this, &GenerateCommitMessageDialog::ready, this, &GenerateCommitMessageDialog::onReady);

Expand Down
2 changes: 1 addition & 1 deletion src/GenerateCommitMessageDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GenerateCommitMessageDialog : public QDialog {
struct Private;
Private *m;
public:
explicit GenerateCommitMessageDialog(QWidget *parent = nullptr);
explicit GenerateCommitMessageDialog(QWidget *parent, const QString &model_name);
~GenerateCommitMessageDialog();
QString text() const;
void generate();
Expand Down
23 changes: 13 additions & 10 deletions src/GenerateCommitMessageDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<item>
<widget class="QListWidget" name="listWidget">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
<set>QAbstractItemView::EditTrigger::NoEditTriggers</set>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand All @@ -34,17 +34,20 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
</spacer>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
Expand Down
12 changes: 6 additions & 6 deletions src/GenerativeAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ enum Type {
};

struct Model {
QString model;
QString name;
Model() = default;
Model(const QString &model)
: model(model)
Model(const QString &name)
: name(name)
{
}
Type type() const
{
if (model.startsWith("gpt-")) {
if (name.startsWith("gpt-")) {
return GPT;
}
if (model.startsWith("claude-")) {
if (name.startsWith("claude-")) {
return CLAUDE;
}
if (model.startsWith("gemini-")) {
if (name.startsWith("gemini-")) {
return GEMINI;
}
return Unknown;
Expand Down
4 changes: 2 additions & 2 deletions src/SettingAiForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SettingAiForm::SettingAiForm(QWidget *parent)
QStringList list;
auto vec =GenerativeAI::available_models();
for (auto &m : vec) {
list.push_back(m.model);
list.push_back(m.name);
}
ui->comboBox_ai_model->addItems(list);
}
Expand Down Expand Up @@ -42,7 +42,7 @@ void SettingAiForm::exchange(bool save)
ui->lineEdit_openai_api_key->setText(settings()->openai_api_key);
ui->lineEdit_anthropic_api_key->setText(settings()->anthropic_api_key);
ui->lineEdit_google_api_key->setText(settings()->google_api_key);
ui->comboBox_ai_model->setCurrentText(settings()->ai_model.model);
ui->comboBox_ai_model->setCurrentText(settings()->ai_model.name);

openai_api_key_ = settings()->openai_api_key;
anthropic_api_key_ = settings()->anthropic_api_key;
Expand Down

0 comments on commit a000dc5

Please sign in to comment.