From 729a5b0d9fcd9054a6bf12d330f0b76fc1e680f3 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Tue, 18 Feb 2025 17:23:19 -0500 Subject: [PATCH] ollama-hpp immediately segfaulted. will try something else Signed-off-by: Jared Van Bortel --- gpt4all-backend-test/CMakeLists.txt | 8 ++++++++ gpt4all-backend-test/src/CMakeLists.txt | 21 +++++++++++++++++++++ gpt4all-backend-test/src/config.cppm.in | 7 +++++++ gpt4all-backend-test/src/main.cpp | 12 ++++++++++++ gpt4all-backend/src/main.cpp | 20 +++++++++++++++----- gpt4all-backend/src/main.cppm | 19 +++++++++++++++++-- 6 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 gpt4all-backend-test/CMakeLists.txt create mode 100644 gpt4all-backend-test/src/CMakeLists.txt create mode 100644 gpt4all-backend-test/src/config.cppm.in create mode 100644 gpt4all-backend-test/src/main.cpp diff --git a/gpt4all-backend-test/CMakeLists.txt b/gpt4all-backend-test/CMakeLists.txt new file mode 100644 index 00000000..fb3151ed --- /dev/null +++ b/gpt4all-backend-test/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.29) +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(src) diff --git a/gpt4all-backend-test/src/CMakeLists.txt b/gpt4all-backend-test/src/CMakeLists.txt new file mode 100644 index 00000000..7b6a4a70 --- /dev/null +++ b/gpt4all-backend-test/src/CMakeLists.txt @@ -0,0 +1,21 @@ +set(TARGET test-backend) + +configure_file(config.cppm.in "${CMAKE_CURRENT_BINARY_DIR}/config.cppm") + +add_executable(${TARGET} + main.cpp +) +target_compile_features(${TARGET} PUBLIC cxx_std_23) +if (CMAKE_COMPILER_IS_GNUCXX) + target_compile_options(${TARGET} PUBLIC -fmodules-ts) +endif() +target_sources(${TARGET} PRIVATE + FILE_SET gpt4all_backend TYPE CXX_MODULES BASE_DIRS + "${CMAKE_CURRENT_BINARY_DIR}" + FILES + "${CMAKE_CURRENT_BINARY_DIR}/config.cppm" +) +gpt4all_add_warning_options(${TARGET}) +target_link_libraries(${TARGET} PRIVATE + gpt4all-backend +) diff --git a/gpt4all-backend-test/src/config.cppm.in b/gpt4all-backend-test/src/config.cppm.in new file mode 100644 index 00000000..997cc0f2 --- /dev/null +++ b/gpt4all-backend-test/src/config.cppm.in @@ -0,0 +1,7 @@ +module; + +#include + +export module gpt4all.test.config; + +export inline QByteArray OLLAMA_URL("@G4A_TEST_OLLAMA_URL@"); diff --git a/gpt4all-backend-test/src/main.cpp b/gpt4all-backend-test/src/main.cpp new file mode 100644 index 00000000..bb8039eb --- /dev/null +++ b/gpt4all-backend-test/src/main.cpp @@ -0,0 +1,12 @@ +import fmt; +import gpt4all.backend.main; +import gpt4all.test.config; + +#include + + +int main() +{ + LLMProvider provider { QLatin1StringView(OLLAMA_URL) }; + fmt::print("Server version: {}", provider.getVersion()); +} diff --git a/gpt4all-backend/src/main.cpp b/gpt4all-backend/src/main.cpp index 386cdda6..b21917f8 100644 --- a/gpt4all-backend/src/main.cpp +++ b/gpt4all-backend/src/main.cpp @@ -2,17 +2,27 @@ module; #include -#include +#include #include module gpt4all.backend.main; -import fmt; +LLMProvider::LLMProvider(QLatin1StringView serverUrl) + : m_serverUrl(serverUrl.data(), serverUrl.size()) + , m_ollama(std::make_unique(m_serverUrl)) + {} -std::string LLMProvider::qstringToSTL(const QString &s) +LLMProvider::~LLMProvider() = default; + +void LLMProvider::setServerUrl(QLatin1StringView serverUrl) { - fmt::format("{}", "foo"); - return s.toStdString(); + m_serverUrl.assign(serverUrl.data(), serverUrl.size()); + m_ollama->setServerURL(m_serverUrl); +} + +QByteArray LLMProvider::getVersion() +{ + return QByteArray(m_ollama->get_version()); } diff --git a/gpt4all-backend/src/main.cppm b/gpt4all-backend/src/main.cppm index c2bc1cad..6ac56b9e 100644 --- a/gpt4all-backend/src/main.cppm +++ b/gpt4all-backend/src/main.cppm @@ -1,12 +1,27 @@ module; +#include #include -#include +#include export module gpt4all.backend.main; +class Ollama; + export class LLMProvider { - static std::string qstringToSTL(const QString &s); +public: + LLMProvider(QLatin1StringView serverUrl); + ~LLMProvider(); + + QLatin1StringView serverUrl() const { return QLatin1StringView(m_serverUrl); } + void setServerUrl(QLatin1StringView serverUrl); + + /// Retrieve the Ollama version, e.g. "0.5.1" + QByteArray getVersion(); + +private: + std::string m_serverUrl; + std::unique_ptr m_ollama; };