refactor: consolidate and rename data generation and service files

This commit is contained in:
Aaron Po
2026-04-11 00:06:23 -04:00
parent 8c572a2d07
commit ae67fa8566
10 changed files with 50 additions and 73 deletions

View File

@@ -104,27 +104,24 @@ FetchContent_MakeAvailable(spdlog)
set(SOURCES
src/main.cpp
# BiergartenDataGenerator methods
src/biergarten_data_generator/constructor.cpp
src/biergarten_data_generator/biergarten_data_generator.cpp
src/biergarten_data_generator/run.cpp
src/biergarten_data_generator/query_cities_with_countries.cpp
src/biergarten_data_generator/generate_breweries.cpp
src/biergarten_data_generator/log_results.cpp
# WikipediaService methods
src/services/wikipedia/constructor.cpp
src/services/wikipedia/wikipedia_service.cpp
src/services/wikipedia/get_summary.cpp
src/services/wikipedia/fetch_extract.cpp
# CURLWebClient and CurlGlobalState methods
src/web_client/curl_global_state_constructor.cpp
src/web_client/curl_global_state_destructor.cpp
src/web_client/curl_web_client_constructor.cpp
src/web_client/curl_web_client_destructor.cpp
src/web_client/curl_global_state.cpp
src/web_client/curl_web_client.cpp
src/web_client/curl_web_client_download_to_file.cpp
src/web_client/curl_web_client_get.cpp
src/web_client/curl_web_client_utils.cpp
src/web_client/curl_web_client_url_encode.cpp
# Data generation modules
src/data_generation/llama/destructor.cpp
src/data_generation/llama/constructor.cpp
src/data_generation/llama/llama_generator.cpp
src/data_generation/llama/generate_brewery.cpp
src/data_generation/llama/generate_user.cpp
src/data_generation/llama/helpers.cpp

View File

@@ -1,12 +1,12 @@
/**
* @file biergarten_data_generator/constructor.cpp
* @file biergarten_data_generator/biergarten_data_generator.cpp
* @brief BiergartenDataGenerator constructor implementation.
*/
#include <utility>
#include "biergarten_data_generator.h"
#include <utility>
BiergartenDataGenerator::BiergartenDataGenerator(
std::shared_ptr<IEnrichmentService> context_service,
std::unique_ptr<DataGenerator> generator)

View File

@@ -1,26 +0,0 @@
/**
* @file data_generation/llama/destructor.cpp
* @brief Releases llama model/context resources and backend state during
* LlamaGenerator teardown to avoid leaks across runs.
*/
#include "data_generation/llama_generator.h"
#include "llama.h"
LlamaGenerator::~LlamaGenerator() {
/**
* Free the inference context (contains KV cache and computation state)
*/
if (context_ != nullptr) {
llama_free(context_);
context_ = nullptr;
}
/**
* Free the loaded model (contains weights and vocabulary)
*/
if (model_ != nullptr) {
llama_model_free(model_);
model_ = nullptr;
}
}

View File

@@ -1,18 +1,20 @@
/**
* @file data_generation/llama/constructor.cpp
* @brief LlamaGenerator constructor implementation.
* @file data_generation/llama/llama_generator.cpp
* @brief LlamaGenerator constructor and destructor implementation.
*/
#include "data_generation/llama_generator.h"
#include <random>
#include <stdexcept>
#include <string>
#include "biergarten_data_generator.h"
#include "data_generation/llama_generator.h"
#include "llama.h"
LlamaGenerator::LlamaGenerator(const ApplicationOptions& options,
const std::string& model_path)
: rng_() {
: rng_(std::random_device{}()) {
if (model_path.empty()) {
throw std::runtime_error("LlamaGenerator: model path must not be empty");
}
@@ -52,5 +54,23 @@ LlamaGenerator::LlamaGenerator(const ApplicationOptions& options,
}
n_ctx_ = options.n_ctx;
Load(model_path);
this->Load(model_path);
}
LlamaGenerator::~LlamaGenerator() {
/**
* Free the inference context (contains KV cache and computation state)
*/
if (context_ != nullptr) {
llama_free(context_);
context_ = nullptr;
}
/**
* Free the loaded model (contains weights and vocabulary)
*/
if (model_ != nullptr) {
llama_model_free(model_);
model_ = nullptr;
}
}

View File

@@ -1,11 +1,11 @@
/**
* @file wikipedia/constructor.cpp
* @file services/wikipedia/wikipedia_service.cpp
* @brief WikipediaService constructor implementation.
*/
#include <utility>
#include "services/wikipedia_service.h"
#include <utility>
WikipediaService::WikipediaService(std::shared_ptr<WebClient> client)
: client_(std::move(client)) {}

View File

@@ -1,6 +1,6 @@
/**
* @file web_client/curl_global_state_constructor.cpp
* @brief CurlGlobalState constructor implementation.
* @file web_client/curl_global_state.cpp
* @brief CurlGlobalState constructor and destructor implementation.
*/
#include <curl/curl.h>
@@ -15,3 +15,5 @@ CurlGlobalState::CurlGlobalState() {
"[CURLWebClient] Failed to initialize libcurl globally");
}
}
CurlGlobalState::~CurlGlobalState() { curl_global_cleanup(); }

View File

@@ -1,10 +0,0 @@
/**
* @file web_client/curl_global_state_destructor.cpp
* @brief CurlGlobalState destructor implementation.
*/
#include <curl/curl.h>
#include "web_client/curl_web_client.h"
CurlGlobalState::~CurlGlobalState() { curl_global_cleanup(); }

View File

@@ -0,0 +1,10 @@
/**
* @file web_client/curl_web_client.cpp
* @brief CURLWebClient constructor and destructor implementation.
*/
#include "web_client/curl_web_client.h"
CURLWebClient::CURLWebClient() = default;
CURLWebClient::~CURLWebClient() = default;

View File

@@ -1,8 +0,0 @@
/**
* @file web_client/curl_web_client_constructor.cpp
* @brief CURLWebClient constructor implementation.
*/
#include "web_client/curl_web_client.h"
CURLWebClient::CURLWebClient() {}

View File

@@ -1,8 +0,0 @@
/**
* @file web_client/curl_web_client_destructor.cpp
* @brief CURLWebClient destructor implementation.
*/
#include "web_client/curl_web_client.h"
CURLWebClient::~CURLWebClient() {}