mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-28 00:07:04 +00:00
WIP: fix build
This commit is contained in:
parent
bcbbe5194a
commit
371971e6ac
@ -34,18 +34,18 @@ auto OllamaProvider::makeGenerationParams(const QMap<GenerationParam, QVariant>
|
|||||||
{ return new OllamaGenerationParams(values); }
|
{ return new OllamaGenerationParams(values); }
|
||||||
|
|
||||||
/// load
|
/// load
|
||||||
OllamaProviderCustom::OllamaProviderCustom(std::shared_ptr<ProviderStore> store, QUuid id, QString name, QUrl baseUrl)
|
OllamaProviderCustom::OllamaProviderCustom(ProviderStore *store, QUuid id, QString name, QUrl baseUrl)
|
||||||
: ModelProvider (std::move(id), std::move(name), std::move(baseUrl))
|
: ModelProvider (std::move(id), std::move(name), std::move(baseUrl))
|
||||||
, ModelProviderCustom(std::move(store))
|
, ModelProviderCustom(store)
|
||||||
{
|
{
|
||||||
if (auto res = m_store->acquire(m_id); !res)
|
if (auto res = m_store->acquire(m_id); !res)
|
||||||
res.error().raise();
|
res.error().raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// create
|
/// create
|
||||||
OllamaProviderCustom::OllamaProviderCustom(std::shared_ptr<ProviderStore> store, QString name, QUrl baseUrl)
|
OllamaProviderCustom::OllamaProviderCustom(ProviderStore *store, QString name, QUrl baseUrl)
|
||||||
: ModelProvider (std::move(name), std::move(baseUrl))
|
: ModelProvider (std::move(name), std::move(baseUrl))
|
||||||
, ModelProviderCustom(std::move(store))
|
, ModelProviderCustom(store)
|
||||||
{
|
{
|
||||||
auto data = m_store->create(m_name, m_baseUrl);
|
auto data = m_store->create(m_name, m_baseUrl);
|
||||||
if (!data)
|
if (!data)
|
||||||
@ -57,8 +57,6 @@ auto OllamaProviderCustom::asData() -> ModelProviderData
|
|||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
.id = m_id,
|
.id = m_id,
|
||||||
.builtin = false,
|
|
||||||
.type = ProviderType::ollama,
|
|
||||||
.custom_details = CustomProviderDetails { m_name, m_baseUrl },
|
.custom_details = CustomProviderDetails { m_name, m_baseUrl },
|
||||||
.provider_details = {},
|
.provider_details = {},
|
||||||
};
|
};
|
||||||
|
@ -104,7 +104,7 @@ OpenaiProviderBuiltin::OpenaiProviderBuiltin(ProviderStore *store, QUuid id, QSt
|
|||||||
if (!res)
|
if (!res)
|
||||||
res.error().raise();
|
res.error().raise();
|
||||||
if (auto maybeData = *res) {
|
if (auto maybeData = *res) {
|
||||||
auto &details = (*maybeData)->openai_details.value();
|
auto &details = std::get<size_t(ProviderType::openai)>((*maybeData)->provider_details);
|
||||||
m_apiKey = details.api_key;
|
m_apiKey = details.api_key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,10 +112,9 @@ OpenaiProviderBuiltin::OpenaiProviderBuiltin(ProviderStore *store, QUuid id, QSt
|
|||||||
auto OpenaiProviderBuiltin::asData() -> ModelProviderData
|
auto OpenaiProviderBuiltin::asData() -> ModelProviderData
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
.id = m_id,
|
.id = m_id,
|
||||||
.type = ProviderType::openai,
|
.custom_details = {},
|
||||||
.custom_details = {},
|
.provider_details = OpenaiProviderDetails { m_apiKey },
|
||||||
.openai_details = OpenaiProviderDetails { m_apiKey },
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,10 +140,9 @@ OpenaiProviderCustom::OpenaiProviderCustom(ProviderStore *store, QString name, Q
|
|||||||
auto OpenaiProviderCustom::asData() -> ModelProviderData
|
auto OpenaiProviderCustom::asData() -> ModelProviderData
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
.id = m_id,
|
.id = m_id,
|
||||||
.type = ProviderType::openai,
|
.custom_details = CustomProviderDetails { m_name, m_baseUrl },
|
||||||
.custom_details = CustomProviderDetails { m_name, m_baseUrl },
|
.provider_details = OpenaiProviderDetails { m_apiKey },
|
||||||
.openai_details = OpenaiProviderDetails { m_apiKey },
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +62,15 @@ public:
|
|||||||
auto supportedGenerationParams() const -> QSet<GenerationParam> override;
|
auto supportedGenerationParams() const -> QSet<GenerationParam> override;
|
||||||
auto makeGenerationParams(const QMap<GenerationParam, QVariant> &values) const -> OpenaiGenerationParams * override;
|
auto makeGenerationParams(const QMap<GenerationParam, QVariant> &values) const -> OpenaiGenerationParams * override;
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void apiKeyChanged(const QString &value);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_apiKey;
|
QString m_apiKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OpenaiProviderBuiltin : public OpenaiProvider, private ModelProviderMutable {
|
class OpenaiProviderBuiltin : public OpenaiProvider, public ModelProviderMutable {
|
||||||
Q_GADGET
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString name READ name CONSTANT)
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
Q_PROPERTY(QUrl baseUrl READ baseUrl CONSTANT)
|
Q_PROPERTY(QUrl baseUrl READ baseUrl CONSTANT)
|
||||||
|
|
||||||
|
@ -63,10 +63,10 @@ ProviderRegistry::ProviderRegistry(PathSet paths)
|
|||||||
void ProviderRegistry::load()
|
void ProviderRegistry::load()
|
||||||
{
|
{
|
||||||
for (auto &p : s_builtinProviders) { // (not all builtin providers are stored)
|
for (auto &p : s_builtinProviders) { // (not all builtin providers are stored)
|
||||||
auto provider = std::make_shared<OpenaiProviderBuiltin>(m_builtinStore, p.id, p.name, p.base_url);
|
auto provider = std::make_shared<OpenaiProviderBuiltin>(&m_builtinStore, p.id, p.name, p.base_url);
|
||||||
auto [_, unique] = m_providers.emplace(p.id, std::move(provider));
|
auto [_, unique] = m_providers.emplace(p.id, std::move(provider));
|
||||||
if (!unique)
|
if (!unique)
|
||||||
throw std::logic_error(fmt::format("duplicate builtin provider id: {}", p.id));
|
throw std::logic_error(fmt::format("duplicate builtin provider id: {}", p.id.toString()));
|
||||||
}
|
}
|
||||||
for (auto &p : m_customStore.list()) { // disk is source of truth for custom providers
|
for (auto &p : m_customStore.list()) { // disk is source of truth for custom providers
|
||||||
if (!p.custom_details) {
|
if (!p.custom_details) {
|
||||||
@ -75,15 +75,17 @@ void ProviderRegistry::load()
|
|||||||
}
|
}
|
||||||
auto &cust = *p.custom_details;
|
auto &cust = *p.custom_details;
|
||||||
std::shared_ptr<ModelProviderCustom> provider;
|
std::shared_ptr<ModelProviderCustom> provider;
|
||||||
switch (p.type) {
|
switch (p.type()) {
|
||||||
using enum ProviderType;
|
using enum ProviderType;
|
||||||
case ollama:
|
case ollama:
|
||||||
provider = std::make_shared<OllamaProviderCustom>(
|
provider = std::make_shared<OllamaProviderCustom>(
|
||||||
&m_customStore, p.id, cust.name, cust.base_url
|
&m_customStore, p.id, cust.name, cust.base_url
|
||||||
);
|
);
|
||||||
|
break;
|
||||||
case openai:
|
case openai:
|
||||||
provider = std::make_shared<OpenaiProviderCustom>(
|
provider = std::make_shared<OpenaiProviderCustom>(
|
||||||
&m_customStore, p.id, cust.name, cust.base_url, p.openai_details.value().api_key
|
&m_customStore, p.id, cust.name, cust.base_url,
|
||||||
|
std::get<size_t(ProviderType::openai)>(p.provider_details).api_key
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
auto [_, unique] = m_providers.emplace(p.id, std::move(provider));
|
auto [_, unique] = m_providers.emplace(p.id, std::move(provider));
|
||||||
|
@ -104,7 +104,7 @@ public:
|
|||||||
[[nodiscard]] auto operator[](const QUuid &id) const -> const T &
|
[[nodiscard]] auto operator[](const QUuid &id) const -> const T &
|
||||||
{ return m_entries.at(id); }
|
{ return m_entries.at(id); }
|
||||||
[[nodiscard]] auto find(const QUuid &id) const -> std::optional<const T *>
|
[[nodiscard]] auto find(const QUuid &id) const -> std::optional<const T *>
|
||||||
{ auto it = m_entries.find(id); return it == m_entries.end() ? std::nullopt : std::optional(&*it); }
|
{ auto it = m_entries.find(id); return it == m_entries.end() ? std::nullopt : std::optional(&it->second); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
auto createImpl(T data, const QString &name) -> DataStoreResult<const T *>;
|
auto createImpl(T data, const QString &name) -> DataStoreResult<const T *>;
|
||||||
|
@ -15,17 +15,17 @@ namespace gpt4all::ui {
|
|||||||
void tag_invoke(const boost::json::value_from_tag &, boost::json::value &jv, ModelProviderData data)
|
void tag_invoke(const boost::json::value_from_tag &, boost::json::value &jv, ModelProviderData data)
|
||||||
{
|
{
|
||||||
auto &obj = jv.emplace_object();
|
auto &obj = jv.emplace_object();
|
||||||
obj = { { "id", data.id },
|
obj = { { "id", json::value_from(data.id) },
|
||||||
{ "builtin", !data.custom_details },
|
{ "builtin", !data.custom_details },
|
||||||
{ "type", data.type() } };
|
{ "type", json::value_from(data.type()) } };
|
||||||
if (auto custom = data.custom_details) {
|
if (auto custom = data.custom_details) {
|
||||||
obj.emplace("name", custom->name);
|
obj.emplace("name", json::value_from(custom->name));
|
||||||
obj.emplace("base_url", custom->base_url);
|
obj.emplace("base_url", json::value_from(custom->base_url));
|
||||||
}
|
}
|
||||||
switch (data.type()) {
|
switch (data.type()) {
|
||||||
using enum ProviderType;
|
using enum ProviderType;
|
||||||
case openai:
|
case openai:
|
||||||
obj.emplace("api_key", std::get<size_t(openai)>(data.provider_details).api_key);
|
obj.emplace("api_key", json::value_from(std::get<size_t(openai)>(data.provider_details).api_key));
|
||||||
case ollama:
|
case ollama:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user