mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-09-22 03:48:08 +00:00
Add new remote model provider view. (#3506)
Signed-off-by: Adam Treat <treat.adam@gmail.com> Signed-off-by: AT <manyoso@users.noreply.github.com> Signed-off-by: Jared Van Bortel <jared@nomic.ai> Co-authored-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
@@ -502,10 +502,11 @@ bool GPT4AllDownloadableModels::filterAcceptsRow(int sourceRow,
|
||||
bool hasDescription = !description.isEmpty();
|
||||
bool isClone = sourceModel()->data(index, ModelList::IsCloneRole).toBool();
|
||||
bool isDiscovered = sourceModel()->data(index, ModelList::IsDiscoveredRole).toBool();
|
||||
bool isOnline = sourceModel()->data(index, ModelList::OnlineRole).toBool();
|
||||
bool satisfiesKeyword = m_keywords.isEmpty();
|
||||
for (const QString &k : m_keywords)
|
||||
satisfiesKeyword = description.contains(k) ? true : satisfiesKeyword;
|
||||
return !isDiscovered && hasDescription && !isClone && satisfiesKeyword;
|
||||
return !isOnline && !isDiscovered && hasDescription && !isClone && satisfiesKeyword;
|
||||
}
|
||||
|
||||
int GPT4AllDownloadableModels::count() const
|
||||
@@ -2356,3 +2357,56 @@ void ModelList::handleDiscoveryItemErrorOccurred(QNetworkReply::NetworkError cod
|
||||
qWarning() << u"ERROR: Discovery item failed with error code \"%1-%2\""_s
|
||||
.arg(code).arg(reply->errorString()).toStdString();
|
||||
}
|
||||
|
||||
QStringList ModelList::remoteModelList(const QString &apiKey, const QUrl &baseUrl)
|
||||
{
|
||||
QStringList modelList;
|
||||
|
||||
// Create the request
|
||||
QNetworkRequest request;
|
||||
request.setUrl(baseUrl.resolved(QUrl("models")));
|
||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||
|
||||
// Add the Authorization header
|
||||
const QString bearerToken = QString("Bearer %1").arg(apiKey);
|
||||
request.setRawHeader("Authorization", bearerToken.toUtf8());
|
||||
|
||||
// Make the GET request
|
||||
QNetworkReply *reply = m_networkManager.get(request);
|
||||
|
||||
// We use a local event loop to wait for the request to complete
|
||||
QEventLoop loop;
|
||||
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
|
||||
// Check for errors
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
// Parse the JSON response
|
||||
const QByteArray responseData = reply->readAll();
|
||||
const QJsonDocument jsonDoc = QJsonDocument::fromJson(responseData);
|
||||
|
||||
if (!jsonDoc.isNull() && jsonDoc.isObject()) {
|
||||
QJsonObject rootObj = jsonDoc.object();
|
||||
QJsonValue dataValue = rootObj.value("data");
|
||||
|
||||
if (dataValue.isArray()) {
|
||||
QJsonArray dataArray = dataValue.toArray();
|
||||
for (const QJsonValue &val : dataArray) {
|
||||
if (val.isObject()) {
|
||||
QJsonObject obj = val.toObject();
|
||||
const QString modelId = obj.value("id").toString();
|
||||
modelList.append(modelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Handle network error (e.g. print it to qDebug)
|
||||
qWarning() << "Error retrieving models:" << reply->errorString();
|
||||
}
|
||||
|
||||
// Clean up
|
||||
reply->deleteLater();
|
||||
|
||||
return modelList;
|
||||
}
|
||||
|
@@ -534,6 +534,8 @@ public:
|
||||
|
||||
Q_INVOKABLE void discoverSearch(const QString &discover);
|
||||
|
||||
Q_INVOKABLE QStringList remoteModelList(const QString &apiKey, const QUrl &baseUrl);
|
||||
|
||||
Q_SIGNALS:
|
||||
void countChanged();
|
||||
void installedModelsChanged();
|
||||
|
Reference in New Issue
Block a user