From 15e8fba9b84738ba32ced33cfae6d97436362236 Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Mon, 4 Nov 2024 09:25:07 -0500 Subject: [PATCH] Remove extra information from jinja. Signed-off-by: Adam Treat --- gpt4all-chat/src/jinja_helpers.cpp | 61 +----------------------------- gpt4all-chat/src/jinja_helpers.h | 20 ---------- 2 files changed, 2 insertions(+), 79 deletions(-) diff --git a/gpt4all-chat/src/jinja_helpers.cpp b/gpt4all-chat/src/jinja_helpers.cpp index 54748d6e9f9e..3f20638b32ec 100644 --- a/gpt4all-chat/src/jinja_helpers.cpp +++ b/gpt4all-chat/src/jinja_helpers.cpp @@ -13,29 +13,6 @@ using namespace std::literals::string_view_literals; - -JinjaResultInfo::~JinjaResultInfo() = default; - -const JinjaFieldMap JinjaResultInfo::s_fields = { - { "collection", [](auto &s) { return s.collection.toStdString(); } }, - { "path", [](auto &s) { return s.path .toStdString(); } }, - { "file", [](auto &s) { return s.file .toStdString(); } }, - { "title", [](auto &s) { return s.title .toStdString(); } }, - { "author", [](auto &s) { return s.author .toStdString(); } }, - { "date", [](auto &s) { return s.date .toStdString(); } }, - { "text", [](auto &s) { return s.text .toStdString(); } }, - { "page", [](auto &s) { return s.page; } }, - { "fileUri", [](auto &s) { return s.fileUri() .toStdString(); } }, -}; - -JinjaPromptAttachment::~JinjaPromptAttachment() = default; - -const JinjaFieldMap JinjaPromptAttachment::s_fields = { - { "url", [](auto &s) { return s.url.toString() .toStdString(); } }, - { "file", [](auto &s) { return s.file() .toStdString(); } }, - { "processedContent", [](auto &s) { return s.processedContent().toStdString(); } }, -}; - std::vector JinjaMessage::GetKeys() const { std::vector result; @@ -49,17 +26,7 @@ auto JinjaMessage::keys() const -> const std::unordered_set & { static const std::unordered_set baseKeys { "role", "content" }; - static const std::unordered_set userKeys - { "role", "content", "sources", "prompt_attachments" }; - switch (m_item->type()) { - using enum ChatItem::Type; - case System: - case Response: - return baseKeys; - case Prompt: - return userKeys; - } - Q_UNREACHABLE(); + return baseKeys; } bool operator==(const JinjaMessage &a, const JinjaMessage &b) @@ -67,19 +34,7 @@ bool operator==(const JinjaMessage &a, const JinjaMessage &b) if (a.m_item == b.m_item) return true; const auto &[ia, ib] = std::tie(*a.m_item, *b.m_item); - auto type = ia.type(); - if (type != ib.type() || ia.value != ib.value) - return false; - - switch (type) { - using enum ChatItem::Type; - case System: - case Response: - return true; - case Prompt: - return ia.sources == ib.sources && ia.promptAttachments == ib.promptAttachments; - } - Q_UNREACHABLE(); + return ia.type() == ib.type() && ia.value == ib.value; } const JinjaFieldMap JinjaMessage::s_fields = { @@ -93,16 +48,4 @@ const JinjaFieldMap JinjaMessage::s_fields = { Q_UNREACHABLE(); } }, { "content", [](auto &i) { return i.value.toStdString(); } }, - { "sources", [](auto &i) { - auto sources = i.sources | views::transform([](auto &r) { - return jinja2::GenericMap([map = std::make_shared(r)] { return map.get(); }); - }); - return jinja2::ValuesList(sources.begin(), sources.end()); - } }, - { "prompt_attachments", [](auto &i) { - auto attachments = i.promptAttachments | views::transform([](auto &pa) { - return jinja2::GenericMap([map = std::make_shared(pa)] { return map.get(); }); - }); - return jinja2::ValuesList(attachments.begin(), attachments.end()); - } }, }; diff --git a/gpt4all-chat/src/jinja_helpers.h b/gpt4all-chat/src/jinja_helpers.h index ddfc3f57050b..9950586cf8cf 100644 --- a/gpt4all-chat/src/jinja_helpers.h +++ b/gpt4all-chat/src/jinja_helpers.h @@ -14,7 +14,6 @@ namespace views = std::views; - template using JinjaFieldMap = std::unordered_map>; @@ -63,25 +62,6 @@ class JinjaResultInfo : public JinjaHelper { friend class JinjaHelper; }; -class JinjaPromptAttachment : public JinjaHelper { -public: - explicit JinjaPromptAttachment(const PromptAttachment &attachment) noexcept - : m_attachment(&attachment) {} - - ~JinjaPromptAttachment() override; - - const PromptAttachment &value() const { return *m_attachment; } - - friend bool operator==(const JinjaPromptAttachment &a, const JinjaPromptAttachment &b) - { return a.m_attachment == b.m_attachment || *a.m_attachment == *b.m_attachment; } - -private: - static const JinjaFieldMap s_fields; - const PromptAttachment *m_attachment; - - friend class JinjaHelper; -}; - class JinjaMessage : public JinjaHelper { public: explicit JinjaMessage(const ChatItem &item) noexcept