mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-23 14:07:58 +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")
|
||||
include(../common/common.cmake)
|
||||
|
||||
add_subdirectory(../gpt4all-backend "${CMAKE_CURRENT_BINARY_DIR}/gpt4all-backend")
|
||||
add_subdirectory(../gpt4all-backend gpt4all-backend)
|
||||
add_subdirectory(src)
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <QCoro/QCoroTask>
|
||||
#include <QLatin1StringView>
|
||||
|
||||
import fmt;
|
||||
@ -10,5 +11,10 @@ using gpt4all::backend::LLMProvider;
|
||||
int main()
|
||||
{
|
||||
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)
|
||||
|
||||
set(FMT_MODULE ON)
|
||||
add_subdirectory(../deps "${CMAKE_CURRENT_BINARY_DIR}/common_deps")
|
||||
add_subdirectory(../deps common_deps)
|
||||
add_subdirectory(src)
|
||||
|
@ -9,6 +9,7 @@ if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
endif()
|
||||
target_sources(${TARGET} PUBLIC
|
||||
FILE_SET gpt4all_backend TYPE CXX_MODULES FILES
|
||||
formatters.cppm
|
||||
main.cppm
|
||||
)
|
||||
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;
|
||||
std::unique_ptr<QNetworkReply> reply(co_await nam.get(QNetworkRequest(m_baseUrl.resolved(u"/api/version"_s))));
|
||||
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
|
||||
co_return QString::fromUtf8(reply->readAll());
|
||||
|
@ -15,8 +15,13 @@ export module gpt4all.backend.main;
|
||||
|
||||
export namespace gpt4all::backend {
|
||||
|
||||
struct NetErr {
|
||||
QNetworkReply::NetworkError error;
|
||||
QString errorString;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using DataOrNetErr = std::expected<T, QNetworkReply::NetworkError>;
|
||||
using DataOrNetErr = std::expected<T, NetErr>;
|
||||
|
||||
|
||||
class LLMProvider {
|
||||
|
@ -144,8 +144,8 @@ configure_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
|
||||
)
|
||||
|
||||
add_subdirectory(../deps "${CMAKE_CURRENT_BINARY_DIR}/common_deps")
|
||||
add_subdirectory(deps)
|
||||
add_subdirectory(../gpt4all-backend gpt4all-backend)
|
||||
add_subdirectory(../gpt4all-backend-old llmodel)
|
||||
|
||||
if (GPT4ALL_TEST)
|
||||
@ -458,7 +458,7 @@ else()
|
||||
target_link_libraries(chat PRIVATE pdfium)
|
||||
endif()
|
||||
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)
|
||||
|
||||
if (APPLE)
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <utility>
|
||||
|
||||
import fmt;
|
||||
import gpt4all.backend.formatters;
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "database.h"
|
||||
#include "tool.h"
|
||||
#include "toolcallparser.h"
|
||||
#include "utils.h" // IWYU pragma: keep
|
||||
#include "xlsxtomd.h"
|
||||
|
||||
#include <QAbstractListModel>
|
||||
@ -41,6 +40,7 @@
|
||||
#include <vector>
|
||||
|
||||
import fmt;
|
||||
import gpt4all.backend.formatters;
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
namespace ranges = std::ranges;
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "database.h"
|
||||
|
||||
#include "mysettings.h"
|
||||
#include "utils.h" // IWYU pragma: keep
|
||||
|
||||
#include <duckx/duckx.hpp>
|
||||
#include <usearch/index.hpp>
|
||||
@ -42,6 +41,7 @@
|
||||
#endif
|
||||
|
||||
import fmt;
|
||||
import gpt4all.backend.formatters;
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
namespace ranges = std::ranges;
|
||||
|
@ -7,8 +7,6 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
import fmt;
|
||||
|
||||
namespace views = std::views;
|
||||
using json = nlohmann::ordered_json;
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "chatmodel.h"
|
||||
#include "modellist.h"
|
||||
#include "mysettings.h"
|
||||
#include "utils.h" // IWYU pragma: keep
|
||||
|
||||
#include <gpt4all-backend/llmodel.h>
|
||||
|
||||
@ -49,6 +48,7 @@
|
||||
#include <vector>
|
||||
|
||||
import fmt;
|
||||
import gpt4all.backend.formatters;
|
||||
|
||||
using namespace std::string_literals;
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
@ -1,42 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QJsonValue>
|
||||
#include <QLatin1StringView> // IWYU pragma: keep
|
||||
#include <QString>
|
||||
#include <QStringView>
|
||||
#include <QUtf8StringView>
|
||||
#include <QVariant>
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string_view>
|
||||
#include <utility> // IWYU pragma: keep
|
||||
|
||||
import fmt;
|
||||
|
||||
// IWYU pragma: no_forward_declare QJsonValue
|
||||
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
|
||||
QJsonObject makeJsonObject(std::initializer_list<std::pair<QLatin1StringView, QJsonValue>> args);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user