From 490eaa14ffb5fa5f466f04ddd12bed7dec177422 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Mon, 21 Oct 2024 12:25:06 -0400 Subject: [PATCH 1/5] server: fix build on Qt 6.8 Qt 6.8 made breaking changes to the QHttpServer API. It does have technology preview status, after all. Signed-off-by: Jared Van Bortel --- gpt4all-chat/src/server.cpp | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/gpt4all-chat/src/server.cpp b/gpt4all-chat/src/server.cpp index b02d59d47ddc..577859a3266b 100644 --- a/gpt4all-chat/src/server.cpp +++ b/gpt4all-chat/src/server.cpp @@ -37,6 +37,10 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) +# include +#endif + using namespace std::string_literals; using namespace Qt::Literals::StringLiterals; @@ -435,7 +439,6 @@ T &parseRequest(T &request, QJsonObject &&obj) Server::Server(Chat *chat) : ChatLLM(chat, true /*isServer*/) , m_chat(chat) - , m_server(nullptr) { connect(this, &Server::threadStarted, this, &Server::start); connect(this, &Server::databaseResultsChanged, this, &Server::handleDatabaseResultsChanged); @@ -457,10 +460,23 @@ static QJsonObject requestFromJson(const QByteArray &request) void Server::start() { m_server = std::make_unique(this); - if (!m_server->listen(QHostAddress::LocalHost, MySettings::globalInstance()->networkPort())) { - qWarning() << "ERROR: Unable to start the server"; +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + auto *tcpServer = new QTcpServer(m_server.get()); +#else + auto *tcpServer = m_server.get(); +#endif + + auto port = MySettings::globalInstance()->networkPort(); + if (!tcpServer->listen(QHostAddress::LocalHost, port)) { + qWarning() << "Server ERROR: Failed to listen on port" << port; return; } +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + if (!m_server->bind(tcpServer)) { + qWarning() << "Server ERROR: Failed to HTTP server to socket" << port; + return; + } +#endif m_server->route("/v1/models", QHttpServerRequest::Method::Get, [](const QHttpServerRequest &) { @@ -600,10 +616,19 @@ void Server::start() } ); - m_server->afterRequest([] (QHttpServerResponse &&resp) { +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + m_server->addAfterRequestHandler(this, [](const QHttpServerRequest &req, QHttpServerResponse &resp) { + Q_UNUSED(req); + auto headers = resp.headers(); + headers.append("Access-Control-Allow-Origin"_L1, "*"_L1); + resp.setHeaders(std::move(headers)); + }); +#else + m_server->afterRequest([](QHttpServerResponse &&resp) { resp.addHeader("Access-Control-Allow-Origin", "*"); return std::move(resp); }); +#endif connect(this, &Server::requestServerNewPromptResponsePair, m_chat, &Chat::serverNewPromptResponsePair, Qt::BlockingQueuedConnection); From 8f0c8e5d112933d66424d84c3a20a597c03081b9 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Mon, 21 Oct 2024 12:27:12 -0400 Subject: [PATCH 2/5] qml: fix missing import for IconLabel Signed-off-by: Jared Van Bortel --- gpt4all-chat/qml/MySettingsStack.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/gpt4all-chat/qml/MySettingsStack.qml b/gpt4all-chat/qml/MySettingsStack.qml index 9f0273ef689a..17901325aba6 100644 --- a/gpt4all-chat/qml/MySettingsStack.qml +++ b/gpt4all-chat/qml/MySettingsStack.qml @@ -2,6 +2,7 @@ import QtCore import QtQuick import QtQuick.Controls import QtQuick.Controls.Basic +import QtQuick.Controls.impl import QtQuick.Layouts import QtQuick.Dialogs import Qt.labs.folderlistmodel From 5c24388450f839ae740ea16129a8d932489333fa Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Mon, 21 Oct 2024 12:27:37 -0400 Subject: [PATCH 3/5] cmake: suppress warning about QTP0004 Signed-off-by: Jared Van Bortel --- gpt4all-chat/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gpt4all-chat/CMakeLists.txt b/gpt4all-chat/CMakeLists.txt index 0950774a0fa2..57d05031e21f 100644 --- a/gpt4all-chat/CMakeLists.txt +++ b/gpt4all-chat/CMakeLists.txt @@ -77,6 +77,10 @@ configure_file( find_package(Qt6 6.4 COMPONENTS Core HttpServer LinguistTools Pdf Quick QuickDialogs2 Sql Svg REQUIRED) +if (QT_KNOWN_POLICY_QTP0004) + qt_policy(SET QTP0004 NEW) # generate extra qmldir files on Qt 6.8+ +endif() + # Get the Qt6Core target properties get_target_property(Qt6Core_INCLUDE_DIRS Qt6::Core INTERFACE_INCLUDE_DIRECTORIES) get_target_property(Qt6Core_LIBRARY_RELEASE Qt6::Core LOCATION_RELEASE) From af72bfbc329a3d4ad1488d6b9483eeb57fc467b3 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Mon, 21 Oct 2024 12:33:01 -0400 Subject: [PATCH 4/5] changelog: add this PR Signed-off-by: Jared Van Bortel --- gpt4all-chat/CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gpt4all-chat/CHANGELOG.md b/gpt4all-chat/CHANGELOG.md index def1c479db30..8800f70b6f60 100644 --- a/gpt4all-chat/CHANGELOG.md +++ b/gpt4all-chat/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). +## [Unreleased] + +### Changed +- Implemented Qt 6.8 compatibility ([#3121](https://github.com/nomic-ai/gpt4all/pull/3121)) + ## [3.4.2] - 2024-10-16 ### Fixed @@ -164,6 +169,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - Fix several Vulkan resource management issues ([#2694](https://github.com/nomic-ai/gpt4all/pull/2694)) - Fix crash/hang when some models stop generating, by showing special tokens ([#2701](https://github.com/nomic-ai/gpt4all/pull/2701)) +[Unreleased]: https://github.com/nomic-ai/gpt4all/compare/v3.4.2...HEAD [3.4.2]: https://github.com/nomic-ai/gpt4all/compare/v3.4.1...v3.4.2 [3.4.1]: https://github.com/nomic-ai/gpt4all/compare/v3.4.0...v3.4.1 [3.4.0]: https://github.com/nomic-ai/gpt4all/compare/v3.3.0...v3.4.0 From f46be0cb2c185447d829d4befc1e081c9eae8ce3 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Mon, 21 Oct 2024 16:25:00 -0400 Subject: [PATCH 5/5] changelog: tweak wording Signed-off-by: Jared Van Bortel --- gpt4all-chat/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gpt4all-chat/CHANGELOG.md b/gpt4all-chat/CHANGELOG.md index 8800f70b6f60..a6e722d38ac6 100644 --- a/gpt4all-chat/CHANGELOG.md +++ b/gpt4all-chat/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] ### Changed -- Implemented Qt 6.8 compatibility ([#3121](https://github.com/nomic-ai/gpt4all/pull/3121)) +- Implement Qt 6.8 compatibility ([#3121](https://github.com/nomic-ai/gpt4all/pull/3121)) ## [3.4.2] - 2024-10-16