Skip to content

Commit

Permalink
Added save_file and load_file methods for text_completer
Browse files Browse the repository at this point in the history
  • Loading branch information
FuexFollets committed Feb 8, 2024
1 parent 9fc14f7 commit 8cd54f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
20 changes: 0 additions & 20 deletions src/lexocraft/llm/text_completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,24 +624,4 @@ namespace lc {

return *this;
}

TextCompleter& TextCompleter::save(const std::filesystem::path& filepath) {
std::ofstream file {filepath};

cereal::BinaryOutputArchive oarchive {file};

oarchive(*this);

return *this;
}

TextCompleter& TextCompleter::load(const std::filesystem::path& filepath) {
std::ifstream file {filepath};

cereal::BinaryInputArchive iarchive {file};

iarchive(*this);

return *this;
}
} // namespace lc
3 changes: 0 additions & 3 deletions src/lexocraft/llm/text_completion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,6 @@ namespace lc {

TextCompleter& create_vector_subdatabases();

TextCompleter& save(const std::filesystem::path& filepath);
TextCompleter& load(const std::filesystem::path& filepath);

TextCompleter();
TextCompleter(const TextCompleter&) = default;
TextCompleter& operator=(const TextCompleter&) = default;
Expand Down
25 changes: 25 additions & 0 deletions src/lexocraft/llm/text_completion_interface.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#include <fstream>

#include <cereal/cereal.hpp>
#include <cereal/types/memory.hpp>

#include <lexocraft/llm/text_completion.hpp>

namespace lc {
Expand Down Expand Up @@ -73,6 +78,26 @@ namespace lc {
return create_vector_subdatabases();
}

TextCompleter& TextCompleter::save_file(const std::filesystem::path& filepath) {
std::ofstream file {filepath};

cereal::BinaryOutputArchive archive {file};

archive(*this);

return *this;
}

TextCompleter& TextCompleter::load_file(const std::filesystem::path& filepath) {
std::ifstream file {filepath};

cereal::BinaryInputArchive archive {file};

archive(*this);

return *this;
}

// -------------------------- Ephermal Memory Accumulator --------------------------
TextCompleter& TextCompleter::set_ephemeral_memory_accumulator_layer_sizes(
const BinaryLayerSizeVectorGenerator_t& binary_layer_size_vector_generator,
Expand Down

0 comments on commit 8cd54f7

Please sign in to comment.