mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-26 15:31:55 +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); }
|
||||
|
||||
/// 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))
|
||||
, ModelProviderCustom(std::move(store))
|
||||
, ModelProviderCustom(store)
|
||||
{
|
||||
if (auto res = m_store->acquire(m_id); !res)
|
||||
res.error().raise();
|
||||
}
|
||||
|
||||
/// 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))
|
||||
, ModelProviderCustom(std::move(store))
|
||||
, ModelProviderCustom(store)
|
||||
{
|
||||
auto data = m_store->create(m_name, m_baseUrl);
|
||||
if (!data)
|
||||
@ -57,8 +57,6 @@ auto OllamaProviderCustom::asData() -> ModelProviderData
|
||||
{
|
||||
return {
|
||||
.id = m_id,
|
||||
.builtin = false,
|
||||
.type = ProviderType::ollama,
|
||||
.custom_details = CustomProviderDetails { m_name, m_baseUrl },
|
||||
.provider_details = {},
|
||||
};
|
||||
|
@ -104,7 +104,7 @@ OpenaiProviderBuiltin::OpenaiProviderBuiltin(ProviderStore *store, QUuid id, QSt
|
||||
if (!res)
|
||||
res.error().raise();
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -112,10 +112,9 @@ OpenaiProviderBuiltin::OpenaiProviderBuiltin(ProviderStore *store, QUuid id, QSt
|
||||
auto OpenaiProviderBuiltin::asData() -> ModelProviderData
|
||||
{
|
||||
return {
|
||||
.id = m_id,
|
||||
.type = ProviderType::openai,
|
||||
.custom_details = {},
|
||||
.openai_details = OpenaiProviderDetails { m_apiKey },
|
||||
.id = m_id,
|
||||
.custom_details = {},
|
||||
.provider_details = OpenaiProviderDetails { m_apiKey },
|
||||
};
|
||||
}
|
||||
|
||||
@ -141,10 +140,9 @@ OpenaiProviderCustom::OpenaiProviderCustom(ProviderStore *store, QString name, Q
|
||||
auto OpenaiProviderCustom::asData() -> ModelProviderData
|
||||
{
|
||||
return {
|
||||
.id = m_id,
|
||||
.type = ProviderType::openai,
|
||||
.custom_details = CustomProviderDetails { m_name, m_baseUrl },
|
||||
.openai_details = OpenaiProviderDetails { m_apiKey },
|
||||
.id = m_id,
|
||||
.custom_details = CustomProviderDetails { m_name, m_baseUrl },
|
||||
.provider_details = OpenaiProviderDetails { m_apiKey },
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -62,12 +62,15 @@ public:
|
||||
auto supportedGenerationParams() const -> QSet<GenerationParam> override;
|
||||
auto makeGenerationParams(const QMap<GenerationParam, QVariant> &values) const -> OpenaiGenerationParams * override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void apiKeyChanged(const QString &value);
|
||||
|
||||
protected:
|
||||
QString m_apiKey;
|
||||
};
|
||||
|
||||
class OpenaiProviderBuiltin : public OpenaiProvider, private ModelProviderMutable {
|
||||
Q_GADGET
|
||||
class OpenaiProviderBuiltin : public OpenaiProvider, public ModelProviderMutable {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ name CONSTANT)
|
||||
Q_PROPERTY(QUrl baseUrl READ baseUrl CONSTANT)
|
||||
|
||||
|
@ -63,10 +63,10 @@ ProviderRegistry::ProviderRegistry(PathSet paths)
|
||||
void ProviderRegistry::load()
|
||||
{
|
||||
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));
|
||||
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
|
||||
if (!p.custom_details) {
|
||||
@ -75,15 +75,17 @@ void ProviderRegistry::load()
|
||||
}
|
||||
auto &cust = *p.custom_details;
|
||||
std::shared_ptr<ModelProviderCustom> provider;
|
||||
switch (p.type) {
|
||||
switch (p.type()) {
|
||||
using enum ProviderType;
|
||||
case ollama:
|
||||
provider = std::make_shared<OllamaProviderCustom>(
|
||||
&m_customStore, p.id, cust.name, cust.base_url
|
||||
);
|
||||
break;
|
||||
case openai:
|
||||
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));
|
||||
|
@ -104,7 +104,7 @@ public:
|
||||
[[nodiscard]] auto operator[](const QUuid &id) const -> const T &
|
||||
{ return m_entries.at(id); }
|
||||
[[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:
|
||||
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)
|
||||
{
|
||||
auto &obj = jv.emplace_object();
|
||||
obj = { { "id", data.id },
|
||||
{ "builtin", !data.custom_details },
|
||||
{ "type", data.type() } };
|
||||
obj = { { "id", json::value_from(data.id) },
|
||||
{ "builtin", !data.custom_details },
|
||||
{ "type", json::value_from(data.type()) } };
|
||||
if (auto custom = data.custom_details) {
|
||||
obj.emplace("name", custom->name);
|
||||
obj.emplace("base_url", custom->base_url);
|
||||
obj.emplace("name", json::value_from(custom->name));
|
||||
obj.emplace("base_url", json::value_from(custom->base_url));
|
||||
}
|
||||
switch (data.type()) {
|
||||
using enum ProviderType;
|
||||
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:
|
||||
;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user