mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-01 11:56:24 +00:00
Add txt and markdown files to attach feature. (#3135)
Signed-off-by: Adam Treat <treat.adam@gmail.com> Signed-off-by: AT <manyoso@users.noreply.github.com> Co-authored-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
parent
da00527101
commit
b19db6c20d
@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
- Add ability to attach text, markdown, and rst files to chat ([#3135](https://github.com/nomic-ai/gpt4all/pull/3135))
|
||||||
- Add feature to minimize to system tray (by [@bgallois](https://github.com/bgallois) in ([#3109](https://github.com/nomic-ai/gpt4all/pull/3109))
|
- Add feature to minimize to system tray (by [@bgallois](https://github.com/bgallois) in ([#3109](https://github.com/nomic-ai/gpt4all/pull/3109))
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -218,6 +218,7 @@ qt_add_qml_module(chat
|
|||||||
qml/MyDialog.qml
|
qml/MyDialog.qml
|
||||||
qml/MyDirectoryField.qml
|
qml/MyDirectoryField.qml
|
||||||
qml/MyFileDialog.qml
|
qml/MyFileDialog.qml
|
||||||
|
qml/MyFileIcon.qml
|
||||||
qml/MyFolderDialog.qml
|
qml/MyFolderDialog.qml
|
||||||
qml/MyFancyLink.qml
|
qml/MyFancyLink.qml
|
||||||
qml/MyMenu.qml
|
qml/MyMenu.qml
|
||||||
@ -252,6 +253,7 @@ qt_add_qml_module(chat
|
|||||||
icons/eject.svg
|
icons/eject.svg
|
||||||
icons/email.svg
|
icons/email.svg
|
||||||
icons/file-doc.svg
|
icons/file-doc.svg
|
||||||
|
icons/file-docx.svg
|
||||||
icons/file-md.svg
|
icons/file-md.svg
|
||||||
icons/file-pdf.svg
|
icons/file-pdf.svg
|
||||||
icons/file-txt.svg
|
icons/file-txt.svg
|
||||||
|
1
gpt4all-chat/icons/file-docx.svg
Normal file
1
gpt4all-chat/icons/file-docx.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"/><line x1="152" y1="96" x2="208" y2="96" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><line x1="152" y1="160" x2="208" y2="160" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><path d="M64,72V40a8,8,0,0,1,8-8H200a8,8,0,0,1,8,8V216a8,8,0,0,1-8,8H72a8,8,0,0,1-8-8V184" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><polyline points="64 104 76 152 92 120 108 152 120 104" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><rect x="32" y="72" width="120" height="112" rx="8" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/></svg>
|
After Width: | Height: | Size: 893 B |
@ -915,30 +915,12 @@ Rectangle {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 5
|
anchors.margins: 5
|
||||||
|
|
||||||
Item {
|
MyFileIcon {
|
||||||
id: attachmentFileIcon
|
iconSize: 40
|
||||||
width: 40
|
fileName: modelData.file
|
||||||
height: 40
|
|
||||||
Image {
|
|
||||||
id: fileIcon
|
|
||||||
anchors.fill: parent
|
|
||||||
visible: false
|
|
||||||
sourceSize.width: 40
|
|
||||||
sourceSize.height: 40
|
|
||||||
mipmap: true
|
|
||||||
source: {
|
|
||||||
return "qrc:/gpt4all/icons/file-xls.svg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ColorOverlay {
|
|
||||||
anchors.fill: fileIcon
|
|
||||||
source: fileIcon
|
|
||||||
color: theme.textColor
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: attachmentFileText
|
|
||||||
width: 295
|
width: 295
|
||||||
height: 40
|
height: 40
|
||||||
text: modelData.file
|
text: modelData.file
|
||||||
@ -1343,32 +1325,11 @@ Rectangle {
|
|||||||
id: title
|
id: title
|
||||||
spacing: 5
|
spacing: 5
|
||||||
Layout.maximumWidth: 180
|
Layout.maximumWidth: 180
|
||||||
Item {
|
MyFileIcon {
|
||||||
Layout.preferredWidth: 24
|
iconSize: 24
|
||||||
Layout.preferredHeight: 24
|
fileName: modelData.file
|
||||||
Image {
|
Layout.preferredWidth: iconSize
|
||||||
id: fileIcon
|
Layout.preferredHeight: iconSize
|
||||||
anchors.fill: parent
|
|
||||||
visible: false
|
|
||||||
sourceSize.width: 24
|
|
||||||
sourceSize.height: 24
|
|
||||||
mipmap: true
|
|
||||||
source: {
|
|
||||||
if (modelData.file.toLowerCase().endsWith(".txt"))
|
|
||||||
return "qrc:/gpt4all/icons/file-txt.svg"
|
|
||||||
else if (modelData.file.toLowerCase().endsWith(".pdf"))
|
|
||||||
return "qrc:/gpt4all/icons/file-pdf.svg"
|
|
||||||
else if (modelData.file.toLowerCase().endsWith(".md"))
|
|
||||||
return "qrc:/gpt4all/icons/file-md.svg"
|
|
||||||
else
|
|
||||||
return "qrc:/gpt4all/icons/file.svg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ColorOverlay {
|
|
||||||
anchors.fill: fileIcon
|
|
||||||
source: fileIcon
|
|
||||||
color: theme.textColor
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Text {
|
Text {
|
||||||
Layout.maximumWidth: 156
|
Layout.maximumWidth: 156
|
||||||
@ -1949,30 +1910,12 @@ Rectangle {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: 5
|
anchors.margins: 5
|
||||||
|
|
||||||
Item {
|
MyFileIcon {
|
||||||
id: attachmentFileIcon2
|
iconSize: 40
|
||||||
width: 40
|
fileName: model.file
|
||||||
height: 40
|
|
||||||
Image {
|
|
||||||
id: fileIcon2
|
|
||||||
anchors.fill: parent
|
|
||||||
visible: false
|
|
||||||
sourceSize.width: 40
|
|
||||||
sourceSize.height: 40
|
|
||||||
mipmap: true
|
|
||||||
source: {
|
|
||||||
return "qrc:/gpt4all/icons/file-xls.svg"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ColorOverlay {
|
|
||||||
anchors.fill: fileIcon2
|
|
||||||
source: fileIcon2
|
|
||||||
color: theme.textColor
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: attachmentFileText2
|
|
||||||
width: 265
|
width: 265
|
||||||
height: 40
|
height: 40
|
||||||
text: model.file
|
text: model.file
|
||||||
@ -2188,7 +2131,7 @@ Rectangle {
|
|||||||
|
|
||||||
MyFileDialog {
|
MyFileDialog {
|
||||||
id: fileDialog
|
id: fileDialog
|
||||||
nameFilters: ["Excel files (*.xlsx)"]
|
nameFilters: ["All Supported Files (*.txt *.md *.rst *.xlsx)", "Text Files (*.txt *.md *.rst)", "Excel Worksheets (*.xlsx)"]
|
||||||
}
|
}
|
||||||
|
|
||||||
MyMenu {
|
MyMenu {
|
||||||
|
41
gpt4all-chat/qml/MyFileIcon.qml
Normal file
41
gpt4all-chat/qml/MyFileIcon.qml
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import QtCore
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Controls
|
||||||
|
import QtQuick.Controls.Basic
|
||||||
|
import Qt5Compat.GraphicalEffects
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: fileIcon
|
||||||
|
property real iconSize: 24
|
||||||
|
property string fileName: ""
|
||||||
|
implicitWidth: iconSize
|
||||||
|
implicitHeight: iconSize
|
||||||
|
|
||||||
|
Image {
|
||||||
|
id: fileImage
|
||||||
|
anchors.fill: parent
|
||||||
|
visible: false
|
||||||
|
sourceSize.width: iconSize
|
||||||
|
sourceSize.height: iconSize
|
||||||
|
mipmap: true
|
||||||
|
source: {
|
||||||
|
if (fileIcon.fileName.toLowerCase().endsWith(".txt"))
|
||||||
|
return "qrc:/gpt4all/icons/file-txt.svg"
|
||||||
|
else if (fileIcon.fileName.toLowerCase().endsWith(".pdf"))
|
||||||
|
return "qrc:/gpt4all/icons/file-pdf.svg"
|
||||||
|
else if (fileIcon.fileName.toLowerCase().endsWith(".md"))
|
||||||
|
return "qrc:/gpt4all/icons/file-md.svg"
|
||||||
|
else if (fileIcon.fileName.toLowerCase().endsWith(".xlsx"))
|
||||||
|
return "qrc:/gpt4all/icons/file-xls.svg"
|
||||||
|
else if (fileIcon.fileName.toLowerCase().endsWith(".docx"))
|
||||||
|
return "qrc:/gpt4all/icons/file-docx.svg"
|
||||||
|
else
|
||||||
|
return "qrc:/gpt4all/icons/file.svg"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ColorOverlay {
|
||||||
|
anchors.fill: fileImage
|
||||||
|
source: fileImage
|
||||||
|
color: theme.textColor
|
||||||
|
}
|
||||||
|
}
|
@ -132,7 +132,13 @@ void Chat::newPromptResponsePair(const QString &prompt, const QList<QUrl> &attac
|
|||||||
Q_ASSERT(url.isLocalFile());
|
Q_ASSERT(url.isLocalFile());
|
||||||
const QString localFilePath = url.toLocalFile();
|
const QString localFilePath = url.toLocalFile();
|
||||||
const QFileInfo info(localFilePath);
|
const QFileInfo info(localFilePath);
|
||||||
Q_ASSERT(info.suffix() == "xlsx"); // We only support excel right now
|
|
||||||
|
Q_ASSERT(
|
||||||
|
info.suffix().toLower() == "xlsx" ||
|
||||||
|
info.suffix().toLower() == "txt" ||
|
||||||
|
info.suffix().toLower() == "md" ||
|
||||||
|
info.suffix().toLower() == "rst"
|
||||||
|
);
|
||||||
|
|
||||||
PromptAttachment attached;
|
PromptAttachment attached;
|
||||||
attached.url = url;
|
attached.url = url;
|
||||||
|
@ -40,6 +40,11 @@ public:
|
|||||||
|
|
||||||
QString processedContent() const
|
QString processedContent() const
|
||||||
{
|
{
|
||||||
|
const QString localFilePath = url.toLocalFile();
|
||||||
|
const QFileInfo info(localFilePath);
|
||||||
|
if (info.suffix().toLower() != "xlsx")
|
||||||
|
return u"## Attached: %1\n\n%2"_s.arg(file(), content);
|
||||||
|
|
||||||
QBuffer buffer;
|
QBuffer buffer;
|
||||||
buffer.setData(content);
|
buffer.setData(content);
|
||||||
buffer.open(QIODevice::ReadOnly);
|
buffer.open(QIODevice::ReadOnly);
|
||||||
|
Loading…
Reference in New Issue
Block a user