mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-09-06 11:00:48 +00:00
Clean up backend code a bit and hide impl. details.
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
#define LLMODEL_MAX_PROMPT_BATCH 128
|
||||
|
||||
class Dlhandle;
|
||||
class LLImplementation;
|
||||
class LLMImplementation;
|
||||
class LLModel {
|
||||
public:
|
||||
using Token = int32_t;
|
||||
@@ -51,17 +51,10 @@ public:
|
||||
virtual void setThreadCount(int32_t /*n_threads*/) {}
|
||||
virtual int32_t threadCount() const { return 1; }
|
||||
|
||||
const LLImplementation& implementation() const {
|
||||
const LLMImplementation& implementation() const {
|
||||
return *m_implementation;
|
||||
}
|
||||
|
||||
static const std::vector<LLImplementation>& implementationList();
|
||||
static const LLImplementation *implementation(std::ifstream& f, const std::string& buildVariant);
|
||||
static LLModel *construct(const std::string &modelPath, std::string buildVariant = "auto");
|
||||
|
||||
static void setImplementationsSearchPath(const std::string& path);
|
||||
static const std::string& implementationsSearchPath();
|
||||
|
||||
protected:
|
||||
// These are pure virtual because subclasses need to implement as the default implementation of
|
||||
// 'prompt' above calls these functions
|
||||
@@ -76,33 +69,37 @@ protected:
|
||||
// shared by all base classes so it isn't virtual
|
||||
void recalculateContext(PromptContext &promptCtx, std::function<bool(bool)> recalculate);
|
||||
|
||||
const LLImplementation *m_implementation = nullptr;
|
||||
const LLMImplementation *m_implementation = nullptr;
|
||||
|
||||
private:
|
||||
friend class LLImplementation;
|
||||
friend class LLMImplementation;
|
||||
};
|
||||
|
||||
class LLImplementation {
|
||||
LLModel *(*construct_)();
|
||||
|
||||
class LLMImplementation {
|
||||
public:
|
||||
LLImplementation(Dlhandle&&);
|
||||
LLImplementation(const LLImplementation&) = delete;
|
||||
LLImplementation(LLImplementation&&);
|
||||
~LLImplementation();
|
||||
LLMImplementation(Dlhandle&&);
|
||||
LLMImplementation(const LLMImplementation&) = delete;
|
||||
LLMImplementation(LLMImplementation&&);
|
||||
~LLMImplementation();
|
||||
|
||||
std::string_view modelType() const { return m_modelType; }
|
||||
std::string_view buildVariant() const { return m_buildVariant; }
|
||||
|
||||
static bool isImplementation(const Dlhandle&);
|
||||
static const std::vector<LLMImplementation>& implementationList();
|
||||
static const LLMImplementation *implementation(std::ifstream& f, const std::string& buildVariant);
|
||||
static LLModel *construct(const std::string &modelPath, std::string buildVariant = "auto");
|
||||
static void setImplementationsSearchPath(const std::string& path);
|
||||
static const std::string& implementationsSearchPath();
|
||||
|
||||
std::string_view modelType, buildVariant;
|
||||
bool (*magicMatch)(std::ifstream& f);
|
||||
Dlhandle *dlhandle;
|
||||
private:
|
||||
bool (*m_magicMatch)(std::ifstream& f);
|
||||
LLModel *(*m_construct)();
|
||||
|
||||
// The only way an implementation should be constructed
|
||||
LLModel *construct() const {
|
||||
auto fres = construct_();
|
||||
fres->m_implementation = this;
|
||||
return fres;
|
||||
}
|
||||
private:
|
||||
std::string_view m_modelType;
|
||||
std::string_view m_buildVariant;
|
||||
Dlhandle *m_dlhandle;
|
||||
};
|
||||
|
||||
#endif // LLMODEL_H
|
||||
|
Reference in New Issue
Block a user