localdocs: small but important fixes to local docs (#2236)

* chat: use .rmodel extension for Nomic Embed

Signed-off-by: Jared Van Bortel <jared@nomic.ai>

* database: fix order of SQL arguments in updateDocument

Signed-off-by: Jared Van Bortel <jared@nomic.ai>

---------

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel 2024-04-18 14:51:13 -04:00 committed by GitHub
parent be93ee75de
commit 271d752701
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 12 deletions

View File

@ -283,10 +283,10 @@ bool ChatLLM::loadModel(const ModelInfo &modelInfo)
QString modelName; QString modelName;
{ {
QFile file(filePath); QFile file(filePath);
file.open(QIODeviceBase::ReadOnly | QIODeviceBase::Text); bool success = file.open(QIODeviceBase::ReadOnly);
QTextStream stream(&file); (void)success;
QString text = stream.readAll(); Q_ASSERT(success);
QJsonDocument doc = QJsonDocument::fromJson(text.toUtf8()); QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
QJsonObject obj = doc.object(); QJsonObject obj = doc.object();
apiKey = obj["apiKey"].toString(); apiKey = obj["apiKey"].toString();
modelName = obj["modelName"].toString(); modelName = obj["modelName"].toString();

View File

@ -410,8 +410,8 @@ bool updateDocument(QSqlQuery &q, int id, qint64 document_time)
{ {
if (!q.prepare(UPDATE_DOCUMENT_TIME_SQL)) if (!q.prepare(UPDATE_DOCUMENT_TIME_SQL))
return false; return false;
q.addBindValue(id);
q.addBindValue(document_time); q.addBindValue(document_time);
q.addBindValue(id);
return q.exec(); return q.exec();
} }

View File

@ -42,12 +42,17 @@ bool EmbeddingLLMWorker::loadModel()
} }
auto filename = fileInfo.fileName(); auto filename = fileInfo.fileName();
bool isNomic = filename.startsWith("nomic-") && filename.endsWith(".txt"); bool isNomic = filename.startsWith("gpt4all-nomic-") && filename.endsWith(".rmodel");
if (isNomic) { if (isNomic) {
QFile file(filePath); QFile file(filePath);
file.open(QIODeviceBase::ReadOnly | QIODeviceBase::Text); if (!file.open(QIODeviceBase::ReadOnly)) {
QTextStream stream(&file); qWarning() << "failed to open" << filePath << ":" << file.errorString();
m_nomicAPIKey = stream.readAll(); m_model = nullptr;
return false;
}
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
QJsonObject obj = doc.object();
m_nomicAPIKey = obj["apiKey"].toString();
file.close(); file.close();
return true; return true;
} }

View File

@ -12,7 +12,7 @@
const char * const KNOWN_EMBEDDING_MODELS[] { const char * const KNOWN_EMBEDDING_MODELS[] {
"all-MiniLM-L6-v2.gguf2.f16.gguf", "all-MiniLM-L6-v2.gguf2.f16.gguf",
"nomic-embed-text-v1.txt", "gpt4all-nomic-embed-text-v1.rmodel",
}; };
QString ModelInfo::id() const QString ModelInfo::id() const
@ -1178,7 +1178,7 @@ void ModelList::updateModelsFromDirectory()
it.next(); it.next();
if (!it.fileInfo().isDir()) { if (!it.fileInfo().isDir()) {
QString filename = it.fileName(); QString filename = it.fileName();
if (filename.startsWith("chatgpt-") && filename.endsWith(".txt")) { if (filename.endsWith(".txt") && (filename.startsWith("chatgpt-") || filename.startsWith("nomic-"))) {
QString apikey; QString apikey;
QString modelname(filename); QString modelname(filename);
modelname.chop(4); // strip ".txt" extension modelname.chop(4); // strip ".txt" extension
@ -1648,7 +1648,7 @@ void ModelList::parseModelsJsonFile(const QByteArray &jsonData, bool save)
"<li>You can apply for an API key <a href=\"https://atlas.nomic.ai/\">with Nomic Atlas.</a></li>"); "<li>You can apply for an API key <a href=\"https://atlas.nomic.ai/\">with Nomic Atlas.</a></li>");
const QString modelName = "Nomic Embed"; const QString modelName = "Nomic Embed";
const QString id = modelName; const QString id = modelName;
const QString modelFilename = "nomic-embed-text-v1.txt"; // FIXME: This should be made to use '.rmodel' as well const QString modelFilename = "gpt4all-nomic-embed-text-v1.rmodel";
if (contains(modelFilename)) if (contains(modelFilename))
changeId(modelFilename, id); changeId(modelFilename, id);
if (!contains(id)) if (!contains(id))