Skip to content

Commit

Permalink
new settings (model path, repeat penalty) w/ tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
apage43 authored and manyoso committed Apr 25, 2023
1 parent cd03c5b commit 15a979b
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 289 deletions.
19 changes: 18 additions & 1 deletion download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Download::Download()
&Download::handleHashAndSaveFinished, Qt::QueuedConnection);
connect(&m_networkManager, &QNetworkAccessManager::sslErrors, this,
&Download::handleSslErrors);
connect(this, &Download::downloadLocalModelsPathChanged, this, &Download::updateModelList);
updateModelList();
m_downloadLocalModelsPath = defaultLocalModelsPath();
}

QList<ModelInfo> Download::modelList() const
Expand All @@ -46,7 +48,22 @@ QList<ModelInfo> Download::modelList() const
return values;
}

QString Download::downloadLocalModelsPath() const
QString Download::downloadLocalModelsPath() const {
return m_downloadLocalModelsPath;
}

void Download::setDownloadLocalModelsPath(const QString &modelPath) {
QString filePath = (modelPath.startsWith("file://") ?
QUrl(modelPath).toLocalFile() : modelPath);
QString canonical = QFileInfo(filePath).canonicalFilePath() + QDir::separator();
qDebug() << "Set model path: " << canonical;
if (m_downloadLocalModelsPath != canonical) {
m_downloadLocalModelsPath = canonical;
emit downloadLocalModelsPathChanged();
}
}

QString Download::defaultLocalModelsPath() const
{
QString localPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
+ QDir::separator();
Expand Down
7 changes: 7 additions & 0 deletions download.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class Download : public QObject
{
Q_OBJECT
Q_PROPERTY(QList<ModelInfo> modelList READ modelList NOTIFY modelListChanged)
Q_PROPERTY(QString downloadLocalModelsPath READ downloadLocalModelsPath
WRITE setDownloadLocalModelsPath
NOTIFY downloadLocalModelsPathChanged)

public:
static Download *globalInstance();
Expand All @@ -58,7 +61,9 @@ class Download : public QObject
Q_INVOKABLE void updateModelList();
Q_INVOKABLE void downloadModel(const QString &modelFile);
Q_INVOKABLE void cancelDownload(const QString &modelFile);
Q_INVOKABLE QString defaultLocalModelsPath() const;
Q_INVOKABLE QString downloadLocalModelsPath() const;
Q_INVOKABLE void setDownloadLocalModelsPath(const QString &modelPath);

private Q_SLOTS:
void handleSslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
Expand All @@ -73,6 +78,7 @@ private Q_SLOTS:
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal, const QString &modelFile);
void downloadFinished(const QString &modelFile);
void modelListChanged();
void downloadLocalModelsPathChanged();
void requestHashAndSave(const QString &hash, const QString &saveFilePath,
QTemporaryFile *tempFile, QNetworkReply *modelReply);

Expand All @@ -83,6 +89,7 @@ private Q_SLOTS:
QMap<QString, ModelInfo> m_modelMap;
QNetworkAccessManager m_networkManager;
QMap<QNetworkReply*, QTemporaryFile*> m_activeDownloads;
QString m_downloadLocalModelsPath;

private:
explicit Download();
Expand Down
8 changes: 5 additions & 3 deletions llm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ bool LLMObject::handleRecalculate(bool isRecalc)
}

bool LLMObject::prompt(const QString &prompt, const QString &prompt_template, int32_t n_predict, int32_t top_k, float top_p,
float temp, int32_t n_batch)
float temp, int32_t n_batch, float repeat_penalty, int32_t repeat_penalty_tokens)
{
if (!isModelLoaded())
return false;
Expand All @@ -300,6 +300,8 @@ bool LLMObject::prompt(const QString &prompt, const QString &prompt_template, in
s_ctx.top_p = top_p;
s_ctx.temp = temp;
s_ctx.n_batch = n_batch;
s_ctx.repeat_penalty = repeat_penalty;
s_ctx.repeat_last_n = repeat_penalty_tokens;
m_llmodel->prompt(instructPrompt.toStdString(), responseFunc, recalcFunc, s_ctx);
m_responseLogits += s_ctx.logits.size() - logitsBefore;
std::string trimmed = trim_whitespace(m_response);
Expand Down Expand Up @@ -345,9 +347,9 @@ bool LLM::isModelLoaded() const
}

void LLM::prompt(const QString &prompt, const QString &prompt_template, int32_t n_predict, int32_t top_k, float top_p,
float temp, int32_t n_batch)
float temp, int32_t n_batch, float repeat_penalty, int32_t repeat_penalty_tokens)
{
emit promptRequested(prompt, prompt_template, n_predict, top_k, top_p, temp, n_batch);
emit promptRequested(prompt, prompt_template, n_predict, top_k, top_p, temp, n_batch, repeat_penalty, repeat_penalty_tokens);
}

void LLM::regenerateResponse()
Expand Down
6 changes: 3 additions & 3 deletions llm.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LLMObject : public QObject

public Q_SLOTS:
bool prompt(const QString &prompt, const QString &prompt_template, int32_t n_predict, int32_t top_k, float top_p,
float temp, int32_t n_batch);
float temp, int32_t n_batch, float repeat_penalty, int32_t repeat_penalty_tokens);
bool loadModel();
void modelNameChangeRequested(const QString &modelName);

Expand Down Expand Up @@ -85,7 +85,7 @@ class LLM : public QObject

Q_INVOKABLE bool isModelLoaded() const;
Q_INVOKABLE void prompt(const QString &prompt, const QString &prompt_template, int32_t n_predict, int32_t top_k, float top_p,
float temp, int32_t n_batch);
float temp, int32_t n_batch, float repeat_penalty, int32_t repeat_penalty_tokens);
Q_INVOKABLE void regenerateResponse();
Q_INVOKABLE void resetResponse();
Q_INVOKABLE void resetContext();
Expand All @@ -111,7 +111,7 @@ class LLM : public QObject
void responseChanged();
void responseInProgressChanged();
void promptRequested(const QString &prompt, const QString &prompt_template, int32_t n_predict, int32_t top_k, float top_p,
float temp, int32_t n_batch);
float temp, int32_t n_batch, float repeat_penalty, int32_t repeat_penalty_tokens);
void regenerateResponseRequested();
void resetResponseRequested();
void resetContextRequested();
Expand Down
8 changes: 6 additions & 2 deletions main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,9 @@ Window {
settingsDialog.maxLength,
settingsDialog.topK, settingsDialog.topP,
settingsDialog.temperature,
settingsDialog.promptBatchSize)
settingsDialog.promptBatchSize,
settingsDialog.repeatPenalty,
settingsDialog.repeatPenaltyTokens)
}
}
}
Expand Down Expand Up @@ -905,7 +907,9 @@ Window {
settingsDialog.topK,
settingsDialog.topP,
settingsDialog.temperature,
settingsDialog.promptBatchSize)
settingsDialog.promptBatchSize,
settingsDialog.repeatPenalty,
settingsDialog.repeatPenaltyTokens)
textInput.text = ""
}
}
Expand Down
2 changes: 1 addition & 1 deletion qml/ModelDownloaderDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ Dialog {
Label {
Layout.alignment: Qt.AlignLeft
Layout.fillWidth: true
text: qsTr("NOTE: models will be downloaded to\n") + Download.downloadLocalModelsPath()
text: qsTr("NOTE: models will be downloaded to\n") + Download.downloadLocalModelsPath
wrapMode: Text.WrapAnywhere
horizontalAlignment: Text.AlignHCenter
color: theme.textColor
Expand Down
Loading

0 comments on commit 15a979b

Please sign in to comment.