Skip to content

Commit

Permalink
#3064 add: AI API base URLS to treewidget and button to search script…
Browse files Browse the repository at this point in the history
… repository

Signed-off-by: Patrizio Bekerle <[email protected]>
  • Loading branch information
pbek committed Aug 1, 2024
1 parent 63b6919 commit 8cef620
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 159 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# QOwnNotes Changelog

## 24.8.1
- In the *AI settings* in the list of AI backends from scripts now also the API base
URL will be shown (for [#3064](https://github.com/pbek/QOwnNotes/issues/3064))
- In addition, a button to search the *Script repository* was added
## 24.8.0
- In the *AI settings* there now are buttons to test the connection to the AI services
(for [#3062](https://github.com/pbek/QOwnNotes/issues/3062))
Expand Down
30 changes: 19 additions & 11 deletions src/dialogs/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4416,21 +4416,23 @@ void SettingsDialog::buildAiScriptingTreeWidget() {
return;
}

for (const auto &key : backendNames.keys()) {
for (const auto &backendId : backendNames.keys()) {
// Continue on groq and openai
if (key == QStringLiteral("groq") || key == QStringLiteral("openai")) {
if (backendId == QStringLiteral("groq") || backendId == QStringLiteral("openai")) {
continue;
}

const QString &name = backendNames.value(key);
const QString &backendName = backendNames.value(backendId);

auto backendItem = new QTreeWidgetItem(ui->aiScriptingTreeWidget);
backendItem->setText(0, name);
backendItem->setToolTip(0, tr("AI backend: %1").arg(key));
backendItem->setData(0, Qt::UserRole, key);
backendItem->setText(0, backendName);
backendItem->setToolTip(0, tr("AI backend: %1").arg(backendId));
backendItem->setData(0, Qt::UserRole, backendId);
backendItem->setText(1, openAiService->getApiBaseUrlForBackend(backendId));
backendItem->setToolTip(1, tr("API base URL").arg(backendId));
backendItem->setFlags(backendItem->flags() & ~Qt::ItemIsSelectable);

auto models = openAiService->getModelsForBackend(key);
auto models = openAiService->getModelsForBackend(backendId);
for (const auto &model : models) {
auto modelItem = new QTreeWidgetItem(backendItem);
modelItem->setText(0, model);
Expand All @@ -4441,23 +4443,29 @@ void SettingsDialog::buildAiScriptingTreeWidget() {
// Add test button in new column
auto testButton = new QPushButton();
testButton->setText(tr("Test"));
testButton->setToolTip(tr("Test connection to %1 (%2)").arg(name, model));
testButton->setToolTip(tr("Test connection to %1 (%2)").arg(backendName, model));
testButton->setIcon(
QIcon::fromTheme(QStringLiteral("network-connect"),
QIcon(":/icons/breeze-qownnotes/16x16/network-connect.svg")));
testButton->setProperty("backend", key);
testButton->setProperty("backend", backendId);
testButton->setProperty("model", model);
connect(testButton, &QPushButton::clicked, this, [this, testButton]() {
QString backend = testButton->property("backend").toString();
QString model = testButton->property("model").toString();
runAiApiTest(backend, model);
});

ui->aiScriptingTreeWidget->setItemWidget(modelItem, 1, testButton);
ui->aiScriptingTreeWidget->setItemWidget(modelItem, 2, testButton);
}
}

ui->aiScriptingTreeWidget->expandAll();
ui->aiScriptingTreeWidget->resizeColumnToContents(0);
ui->aiScriptingTreeWidget->resizeColumnToContents(1);
}
ui->aiScriptingTreeWidget->resizeColumnToContents(2);
}

void SettingsDialog::on_searchScriptRepositoryButton_clicked() {
searchScriptInRepository();
buildAiScriptingTreeWidget();
}
2 changes: 2 additions & 0 deletions src/dialogs/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ class SettingsDialog : public MasterDialog {

void on_openAiApiKeyLineEdit_textChanged(const QString &arg1);

void on_searchScriptRepositoryButton_clicked();

private:
Ui::SettingsDialog *ui;
QStatusBar *noteFolderRemotePathTreeStatusBar;
Expand Down
Loading

0 comments on commit 8cef620

Please sign in to comment.