mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-23 22:18:38 +00:00
WIP (hit a clang bug causing an incorrect compiler error)
This commit is contained in:
parent
bca31e6517
commit
ebe6352fc8
@ -4,5 +4,5 @@ project(gpt4all-backend-test VERSION 0.1 LANGUAGES CXX)
|
|||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||||
include(../common/common.cmake)
|
include(../common/common.cmake)
|
||||||
|
|
||||||
add_subdirectory(../gpt4all-backend "${CMAKE_CURRENT_BINARY_DIR}/gpt4all-backend")
|
add_subdirectory(../gpt4all-backend gpt4all-backend)
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <QCoro/QCoroTask>
|
||||||
#include <QLatin1StringView>
|
#include <QLatin1StringView>
|
||||||
|
|
||||||
import fmt;
|
import fmt;
|
||||||
@ -10,5 +11,10 @@ using gpt4all::backend::LLMProvider;
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
LLMProvider provider(OLLAMA_URL);
|
LLMProvider provider(OLLAMA_URL);
|
||||||
fmt::print("Server version: {}", provider.getVersion());
|
auto version = QCoro::waitFor(provider.getVersion());
|
||||||
|
if (version) {
|
||||||
|
fmt::print("Server version: {}", *version);
|
||||||
|
} else {
|
||||||
|
fmt::print("Network error: {}", version.unexpected().errorString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,5 @@ include(../common/common.cmake)
|
|||||||
find_package(Qt6 6.8 COMPONENTS Concurrent Core Network REQUIRED)
|
find_package(Qt6 6.8 COMPONENTS Concurrent Core Network REQUIRED)
|
||||||
|
|
||||||
set(FMT_MODULE ON)
|
set(FMT_MODULE ON)
|
||||||
add_subdirectory(../deps "${CMAKE_CURRENT_BINARY_DIR}/common_deps")
|
add_subdirectory(../deps common_deps)
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
@ -9,6 +9,7 @@ if (CMAKE_COMPILER_IS_GNUCXX)
|
|||||||
endif()
|
endif()
|
||||||
target_sources(${TARGET} PUBLIC
|
target_sources(${TARGET} PUBLIC
|
||||||
FILE_SET gpt4all_backend TYPE CXX_MODULES FILES
|
FILE_SET gpt4all_backend TYPE CXX_MODULES FILES
|
||||||
|
formatters.cppm
|
||||||
main.cppm
|
main.cppm
|
||||||
)
|
)
|
||||||
gpt4all_add_warning_options(${TARGET})
|
gpt4all_add_warning_options(${TARGET})
|
||||||
|
32
gpt4all-backend/src/formatters.cppm
Normal file
32
gpt4all-backend/src/formatters.cppm
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
module;
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QString>
|
||||||
|
#include <QStringView>
|
||||||
|
#include <QUtf8StringView>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
export module gpt4all.backend.formatters;
|
||||||
|
import fmt;
|
||||||
|
|
||||||
|
|
||||||
|
// fmtlib formatters for QString and QVariant
|
||||||
|
|
||||||
|
#define MAKE_FORMATTER(type, conversion) \
|
||||||
|
export template <> \
|
||||||
|
struct fmt::formatter<type, char> : fmt::formatter<std::string_view, char> { \
|
||||||
|
template <typename FmtContext> \
|
||||||
|
FmtContext::iterator format(const type &value, FmtContext &ctx) const \
|
||||||
|
{ \
|
||||||
|
auto valueUtf8 = (conversion); \
|
||||||
|
std::string_view view(valueUtf8.cbegin(), valueUtf8.cend()); \
|
||||||
|
return formatter<std::string_view, char>::format(view, ctx); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
MAKE_FORMATTER(QUtf8StringView, value );
|
||||||
|
MAKE_FORMATTER(QStringView, value.toUtf8() );
|
||||||
|
MAKE_FORMATTER(QString, value.toUtf8() );
|
||||||
|
MAKE_FORMATTER(QVariant, value.toString().toUtf8());
|
@ -24,7 +24,7 @@ auto LLMProvider::getVersion() const -> QCoro::Task<DataOrNetErr<QString>>
|
|||||||
QNetworkAccessManager nam;
|
QNetworkAccessManager nam;
|
||||||
std::unique_ptr<QNetworkReply> reply(co_await nam.get(QNetworkRequest(m_baseUrl.resolved(u"/api/version"_s))));
|
std::unique_ptr<QNetworkReply> reply(co_await nam.get(QNetworkRequest(m_baseUrl.resolved(u"/api/version"_s))));
|
||||||
if (auto err = reply->error())
|
if (auto err = reply->error())
|
||||||
co_return std::unexpected(err);
|
co_return std::unexpected(NetErr{ err, reply->errorString() });
|
||||||
|
|
||||||
// TODO(jared): parse JSON here instead of just returning the data
|
// TODO(jared): parse JSON here instead of just returning the data
|
||||||
co_return QString::fromUtf8(reply->readAll());
|
co_return QString::fromUtf8(reply->readAll());
|
||||||
|
@ -15,8 +15,13 @@ export module gpt4all.backend.main;
|
|||||||
|
|
||||||
export namespace gpt4all::backend {
|
export namespace gpt4all::backend {
|
||||||
|
|
||||||
|
struct NetErr {
|
||||||
|
QNetworkReply::NetworkError error;
|
||||||
|
QString errorString;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using DataOrNetErr = std::expected<T, QNetworkReply::NetworkError>;
|
using DataOrNetErr = std::expected<T, NetErr>;
|
||||||
|
|
||||||
|
|
||||||
class LLMProvider {
|
class LLMProvider {
|
||||||
|
@ -144,8 +144,8 @@ configure_file(
|
|||||||
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
|
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_subdirectory(../deps "${CMAKE_CURRENT_BINARY_DIR}/common_deps")
|
|
||||||
add_subdirectory(deps)
|
add_subdirectory(deps)
|
||||||
|
add_subdirectory(../gpt4all-backend gpt4all-backend)
|
||||||
add_subdirectory(../gpt4all-backend-old llmodel)
|
add_subdirectory(../gpt4all-backend-old llmodel)
|
||||||
|
|
||||||
if (GPT4ALL_TEST)
|
if (GPT4ALL_TEST)
|
||||||
@ -458,7 +458,7 @@ else()
|
|||||||
target_link_libraries(chat PRIVATE pdfium)
|
target_link_libraries(chat PRIVATE pdfium)
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(chat
|
target_link_libraries(chat
|
||||||
PRIVATE llmodel nlohmann_json::nlohmann_json SingleApplication fmt::fmt duckx::duckx QXlsx)
|
PRIVATE gpt4all-backend llmodel nlohmann_json::nlohmann_json SingleApplication fmt::fmt duckx::duckx QXlsx)
|
||||||
target_include_directories(chat PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps/minja/include)
|
target_include_directories(chat PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps/minja/include)
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
import fmt;
|
import fmt;
|
||||||
|
import gpt4all.backend.formatters;
|
||||||
|
|
||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "tool.h"
|
#include "tool.h"
|
||||||
#include "toolcallparser.h"
|
#include "toolcallparser.h"
|
||||||
#include "utils.h" // IWYU pragma: keep
|
|
||||||
#include "xlsxtomd.h"
|
#include "xlsxtomd.h"
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
@ -41,6 +40,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
import fmt;
|
import fmt;
|
||||||
|
import gpt4all.backend.formatters;
|
||||||
|
|
||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
namespace ranges = std::ranges;
|
namespace ranges = std::ranges;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
#include "mysettings.h"
|
#include "mysettings.h"
|
||||||
#include "utils.h" // IWYU pragma: keep
|
|
||||||
|
|
||||||
#include <duckx/duckx.hpp>
|
#include <duckx/duckx.hpp>
|
||||||
#include <usearch/index.hpp>
|
#include <usearch/index.hpp>
|
||||||
@ -42,6 +41,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
import fmt;
|
import fmt;
|
||||||
|
import gpt4all.backend.formatters;
|
||||||
|
|
||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
namespace ranges = std::ranges;
|
namespace ranges = std::ranges;
|
||||||
|
@ -7,8 +7,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
import fmt;
|
|
||||||
|
|
||||||
namespace views = std::views;
|
namespace views = std::views;
|
||||||
using json = nlohmann::ordered_json;
|
using json = nlohmann::ordered_json;
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
#include "chatmodel.h"
|
#include "chatmodel.h"
|
||||||
#include "modellist.h"
|
#include "modellist.h"
|
||||||
#include "mysettings.h"
|
#include "mysettings.h"
|
||||||
#include "utils.h" // IWYU pragma: keep
|
|
||||||
|
|
||||||
#include <gpt4all-backend/llmodel.h>
|
#include <gpt4all-backend/llmodel.h>
|
||||||
|
|
||||||
@ -49,6 +48,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
import fmt;
|
import fmt;
|
||||||
|
import gpt4all.backend.formatters;
|
||||||
|
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
using namespace Qt::Literals::StringLiterals;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
|
@ -1,42 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QByteArray>
|
|
||||||
#include <QJsonValue>
|
#include <QJsonValue>
|
||||||
#include <QLatin1StringView> // IWYU pragma: keep
|
#include <QLatin1StringView> // IWYU pragma: keep
|
||||||
#include <QString>
|
|
||||||
#include <QStringView>
|
|
||||||
#include <QUtf8StringView>
|
|
||||||
#include <QVariant>
|
|
||||||
|
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <string_view>
|
|
||||||
#include <utility> // IWYU pragma: keep
|
#include <utility> // IWYU pragma: keep
|
||||||
|
|
||||||
import fmt;
|
|
||||||
|
|
||||||
// IWYU pragma: no_forward_declare QJsonValue
|
// IWYU pragma: no_forward_declare QJsonValue
|
||||||
class QJsonObject;
|
class QJsonObject;
|
||||||
|
|
||||||
|
|
||||||
// fmtlib formatters for QString and QVariant
|
|
||||||
|
|
||||||
#define MAKE_FORMATTER(type, conversion) \
|
|
||||||
template <> \
|
|
||||||
struct fmt::formatter<type, char>: fmt::formatter<std::string_view, char> { \
|
|
||||||
template <typename FmtContext> \
|
|
||||||
FmtContext::iterator format(const type &value, FmtContext &ctx) const \
|
|
||||||
{ \
|
|
||||||
auto valueUtf8 = (conversion); \
|
|
||||||
std::string_view view(valueUtf8.cbegin(), valueUtf8.cend()); \
|
|
||||||
return formatter<std::string_view, char>::format(view, ctx); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
MAKE_FORMATTER(QUtf8StringView, value );
|
|
||||||
MAKE_FORMATTER(QStringView, value.toUtf8() );
|
|
||||||
MAKE_FORMATTER(QString, value.toUtf8() );
|
|
||||||
MAKE_FORMATTER(QVariant, value.toString().toUtf8());
|
|
||||||
|
|
||||||
// alternative to QJsonObject's initializer_list constructor that accepts Latin-1 strings
|
// alternative to QJsonObject's initializer_list constructor that accepts Latin-1 strings
|
||||||
QJsonObject makeJsonObject(std::initializer_list<std::pair<QLatin1StringView, QJsonValue>> args);
|
QJsonObject makeJsonObject(std::initializer_list<std::pair<QLatin1StringView, QJsonValue>> args);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user