Add the ability to change the directory via text field not just 'browse' button.

pull/821/head
Adam Treat 1 year ago
parent 25ee51e2ca
commit 55055ca983

@ -94,6 +94,7 @@ qt_add_qml_module(chat
qml/Theme.qml
qml/MyButton.qml
qml/MyComboBox.qml
qml/MyDirectoryField.qml
qml/MyTextField.qml
qml/MyCheckBox.qml
qml/MyBusyIndicator.qml

@ -63,6 +63,22 @@ bool LLM::checkForUpdates() const
return QProcess::startDetached(fileName);
}
bool LLM::directoryExists(const QString &path) const
{
const QUrl url(path);
const QString localFilePath = url.isLocalFile() ? url.toLocalFile() : path;
const QFileInfo info(localFilePath);
return info.exists() && info.isDir();
}
bool LLM::fileExists(const QString &path) const
{
const QUrl url(path);
const QString localFilePath = url.isLocalFile() ? url.toLocalFile() : path;
const QFileInfo info(localFilePath);
return info.exists() && info.isFile();
}
int32_t LLM::threadCount() const
{
return m_threadCount;

@ -25,6 +25,8 @@ public:
bool compatHardware() const { return m_compatHardware; }
Q_INVOKABLE bool checkForUpdates() const;
Q_INVOKABLE bool directoryExists(const QString &path) const;
Q_INVOKABLE bool fileExists(const QString &path) const;
Q_SIGNALS:
void chatListModelChanged();

@ -9,8 +9,8 @@ import localdocs
Item {
id: root
property string collection: ""
property string folder_path: ""
property alias collection: collection.text
property alias folder_path: folderEdit.text
property int defaultChunkSize: 256
property int defaultRetrievalSize: 3
@ -60,24 +60,19 @@ Item {
placeholderTextColor: theme.mutedTextColor
ToolTip.text: qsTr("Name of the collection to add (Required)")
ToolTip.visible: hovered
onEditingFinished: {
root.collection = text
}
Accessible.role: Accessible.EditableText
Accessible.name: collection.text
Accessible.description: ToolTip.text
}
MyTextField {
id: folderLabel
MyDirectoryField {
id: folderEdit
anchors.left: collection.right
anchors.leftMargin: 10
anchors.right: browseButton.left
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
text: root.folder_path
readOnly: true
color: theme.textColor
placeholderText: qsTr("Folder path...")
placeholderTextColor: theme.mutedTextColor
ToolTip.text: qsTr("Folder path to documents (Required)")
@ -100,7 +95,7 @@ Item {
text: qsTr("Add")
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
enabled: root.collection !== "" && root.folder_path != ""
enabled: root.collection !== "" && root.folder_path !== "" && folderEdit.isValid
Accessible.role: Accessible.Button
Accessible.name: text
Accessible.description: qsTr("Add button")

@ -386,7 +386,8 @@ Dialog {
title: "Please choose a directory"
currentFolder: "file://" + Download.downloadLocalModelsPath
onAccepted: {
Download.downloadLocalModelsPath = selectedFolder
modelPathDisplayField.text = selectedFolder
Download.downloadLocalModelsPath = modelPathDisplayField.text
settings.modelPath = Download.downloadLocalModelsPath
settings.sync()
}
@ -398,20 +399,23 @@ Dialog {
Layout.row: 1
Layout.column: 0
}
TextField {
id: modelPathDisplayLabel
MyDirectoryField {
id: modelPathDisplayField
text: Download.downloadLocalModelsPath
readOnly: true
color: theme.textColor
Layout.fillWidth: true
ToolTip.text: qsTr("Path where model files will be downloaded to")
ToolTip.visible: hovered
Accessible.role: Accessible.ToolTip
Accessible.name: modelPathDisplayLabel.text
Accessible.name: modelPathDisplayField.text
Accessible.description: ToolTip.text
background: Rectangle {
color: theme.backgroundLighter
radius: 10
onEditingFinished: {
if (isValid) {
Download.downloadLocalModelsPath = modelPathDisplayField.text
settings.modelPath = Download.downloadLocalModelsPath
settings.sync()
} else {
text = Download.downloadLocalModelsPath
}
}
}
MyButton {

@ -0,0 +1,17 @@
import QtCore
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Basic
import llm
TextField {
id: myDirectoryField
padding: 10
property bool isValid: LLM.directoryExists(text)
color: text === "" || isValid ? theme.textColor : theme.textErrorColor
background: Rectangle {
implicitWidth: 150
color: theme.backgroundLighter
radius: 10
}
}

@ -651,7 +651,8 @@ Dialog {
title: "Please choose a directory"
currentFolder: "file://" + Download.downloadLocalModelsPath
onAccepted: {
Download.downloadLocalModelsPath = selectedFolder
modelPathDisplayField.text = selectedFolder
Download.downloadLocalModelsPath = modelPathDisplayField.text
settings.modelPath = Download.downloadLocalModelsPath
settings.sync()
}
@ -663,24 +664,26 @@ Dialog {
Layout.row: 2
Layout.column: 0
}
TextField {
id: modelPathDisplayLabel
MyDirectoryField {
id: modelPathDisplayField
text: Download.downloadLocalModelsPath
readOnly: true
color: theme.textColor
implicitWidth: 300
padding: 10
Layout.row: 2
Layout.column: 1
Layout.fillWidth: true
ToolTip.text: qsTr("Path where model files will be downloaded to")
ToolTip.visible: hovered
Accessible.role: Accessible.ToolTip
Accessible.name: modelPathDisplayLabel.text
Accessible.name: modelPathDisplayField.text
Accessible.description: ToolTip.text
background: Rectangle {
color: theme.backgroundLighter
radius: 10
onEditingFinished: {
if (isValid) {
Download.downloadLocalModelsPath = modelPathDisplayField.text
settings.modelPath = Download.downloadLocalModelsPath
settings.sync()
} else {
text = Download.downloadLocalModelsPath
}
}
}
MyButton {

Loading…
Cancel
Save