hf_text-generation-inference/backends/llamacpp/csrc/ffi.hpp

50 lines
1.2 KiB
C++
Raw Normal View History

2024-10-24 01:56:40 -06:00
//
// Created by mfuntowicz on 10/23/24.
//
#ifndef TGI_LLAMA_CPP_BACKEND_FFI_HPP
#define TGI_LLAMA_CPP_BACKEND_FFI_HPP
#include <exception>
#include <filesystem>
#include <string_view>
#include <spdlog/spdlog.h>
2024-10-24 01:56:40 -06:00
#include "backend.hpp"
namespace huggingface::tgi::backends::llamacpp::impl {
class LlamaCppBackendImpl;
}
#include "backends/llamacpp/src/lib.rs.h"
2024-10-24 01:56:40 -06:00
namespace huggingface::tgi::backends::llamacpp::impl {
class LlamaCppBackendException : std::exception {
};
2024-10-24 01:56:40 -06:00
class LlamaCppBackendImpl {
private:
2024-10-29 15:30:36 -06:00
BackendBase _inner;
2024-10-24 01:56:40 -06:00
public:
2024-10-29 15:30:36 -06:00
LlamaCppBackendImpl(llama_model *model) : _inner(model) {}
2024-10-24 01:56:40 -06:00
};
std::unique_ptr<LlamaCppBackendImpl> CreateLlamaCppBackendImpl(rust::Str modelPath, uint16_t nThreads) {
const auto cxxPath = std::string_view(modelPath);
if (auto maybe = TgiLlamaCppBackend::FromGGUF(std::filesystem::path(cxxPath), nThreads); maybe.has_value()) {
auto [model, context] = *maybe;
return std::make_unique<LlamaCppBackendImpl>(model, context);
} else {
throw LlamaCppBackendException();
}
}
2024-10-24 01:56:40 -06:00
}
#endif //TGI_LLAMA_CPP_BACKEND_FFI_HPP