gui: add 'Embed' button to call KIClient::embed and display resulting vector dimension

This commit is contained in:
Χγφτ Kompanion 2025-10-19 08:33:52 +02:00
parent 2ee757b64a
commit 1e15a96bbe
1 changed files with 22 additions and 1 deletions

View File

@ -37,10 +37,31 @@ public:
m_chatInput = new QLineEdit(mainWidget); m_chatInput = new QLineEdit(mainWidget);
layout->addWidget(m_chatInput); layout->addWidget(m_chatInput);
QHBoxLayout *row = new QHBoxLayout();
QPushButton *sendButton = new QPushButton("Send", mainWidget); QPushButton *sendButton = new QPushButton("Send", mainWidget);
layout->addWidget(sendButton); QPushButton *embedButton = new QPushButton("Embed", mainWidget);
row->addWidget(sendButton);
row->addWidget(embedButton);
layout->addLayout(row);
connect(sendButton, &QPushButton::clicked, this, &MainWindow::sendMessage); connect(sendButton, &QPushButton::clicked, this, &MainWindow::sendMessage);
connect(embedButton, &QPushButton::clicked, this, [this]() {
const QString text = m_chatInput->text().trimmed();
if (text.isEmpty()) return;
KI::KIEmbedOptions opts; opts.model = "bge-m3:latest"; // simple default
QFuture<KI::KIEmbeddingResult> fut = m_kompanionClient->embed(QStringList{text}, opts);
auto *watch = new QFutureWatcher<KI::KIEmbeddingResult>(this);
connect(watch, &QFutureWatcher<KI::KIEmbeddingResult>::finished, this, [this, watch]() {
const auto res = watch->result();
if (!res.vectors.isEmpty()) {
insertText(QString("[embed %1] dim=%2\n").arg(res.model).arg(res.vectors.first().size()));
} else {
insertText("[embed] no result\n");
}
watch->deleteLater();
});
watch->setFuture(fut);
});
// Setup KI // Setup KI
m_ollamaProvider = new KI::OllamaProvider(this); m_ollamaProvider = new KI::OllamaProvider(this);