mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-04-05 18:09:04 +00:00
Implement Llama-based brewery and user data generation; remove mock generator and related files
This commit is contained in:
25
pipeline/includes/data_generator.h
Normal file
25
pipeline/includes/data_generator.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
struct BreweryResult {
|
||||
std::string name;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
struct UserResult {
|
||||
std::string username;
|
||||
std::string bio;
|
||||
};
|
||||
|
||||
class IDataGenerator {
|
||||
public:
|
||||
virtual ~IDataGenerator() = default;
|
||||
|
||||
virtual void load(const std::string &modelPath) = 0;
|
||||
|
||||
virtual BreweryResult generateBrewery(const std::string &cityName,
|
||||
const std::string ®ionContext) = 0;
|
||||
|
||||
virtual UserResult generateUser(const std::string &locale) = 0;
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/// @brief Deterministic mock brewery text generator used in pipeline output.
|
||||
class LlamaBreweryGenerator {
|
||||
private:
|
||||
const std::vector<std::string> breweryAdjectives = {
|
||||
"Craft", "Heritage", "Local", "Artisan",
|
||||
"Pioneer", "Golden", "Modern", "Classic"};
|
||||
|
||||
const std::vector<std::string> breweryNouns = {
|
||||
"Brewing Co.", "Brewery", "Bier Haus", "Taproom",
|
||||
"Works", "House", "Fermentery", "Ale Co."};
|
||||
|
||||
const std::vector<std::string> descriptions = {
|
||||
"Handcrafted pale ales and seasonal IPAs with local ingredients.",
|
||||
"Traditional lagers and experimental sours in small batches.",
|
||||
"Award-winning stouts and wildly hoppy blonde ales.",
|
||||
"Craft brewery specializing in Belgian-style triples and dark porters.",
|
||||
"Modern brewery blending tradition with bold experimental flavors."};
|
||||
|
||||
public:
|
||||
/// @brief Generated brewery payload for one city.
|
||||
struct Brewery {
|
||||
std::string name;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
/// @brief Loads model resources (mock implementation in this project).
|
||||
void LoadModel(const std::string &modelPath);
|
||||
|
||||
/// @brief Generates deterministic brewery text for a city and seed.
|
||||
Brewery GenerateBrewery(const std::string &cityName, int seed);
|
||||
};
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "database.h"
|
||||
#include "stream_parser.h"
|
||||
#include "work_queue.h"
|
||||
#include <string>
|
||||
|
||||
/// @brief Loads world-city JSON data into SQLite through streaming parsing.
|
||||
|
||||
24
pipeline/includes/llama_generator.h
Normal file
24
pipeline/includes/llama_generator.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "data_generator.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
struct llama_model;
|
||||
struct llama_context;
|
||||
|
||||
class LlamaGenerator final : public IDataGenerator {
|
||||
public:
|
||||
~LlamaGenerator() override;
|
||||
|
||||
void load(const std::string &modelPath) override;
|
||||
BreweryResult generateBrewery(const std::string &cityName,
|
||||
const std::string ®ionContext) override;
|
||||
UserResult generateUser(const std::string &locale) override;
|
||||
|
||||
private:
|
||||
std::string infer(const std::string &prompt, int maxTokens = 256);
|
||||
|
||||
llama_model *model_ = nullptr;
|
||||
llama_context *context_ = nullptr;
|
||||
};
|
||||
23
pipeline/includes/mock_generator.h
Normal file
23
pipeline/includes/mock_generator.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "data_generator.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class MockGenerator final : public IDataGenerator {
|
||||
public:
|
||||
void load(const std::string &modelPath) override;
|
||||
BreweryResult generateBrewery(const std::string &cityName,
|
||||
const std::string ®ionContext) override;
|
||||
UserResult generateUser(const std::string &locale) override;
|
||||
|
||||
private:
|
||||
static std::size_t deterministicHash(const std::string &a,
|
||||
const std::string &b);
|
||||
|
||||
static const std::vector<std::string> kBreweryAdjectives;
|
||||
static const std::vector<std::string> kBreweryNouns;
|
||||
static const std::vector<std::string> kBreweryDescriptions;
|
||||
static const std::vector<std::string> kUsernames;
|
||||
static const std::vector<std::string> kBios;
|
||||
};
|
||||
@@ -1,63 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <queue>
|
||||
|
||||
/// @brief Bounded thread-safe queue with blocking push/pop and shutdown.
|
||||
template <typename T> class WorkQueue {
|
||||
private:
|
||||
std::queue<T> queue;
|
||||
std::mutex mutex;
|
||||
std::condition_variable cv_not_empty;
|
||||
std::condition_variable cv_not_full;
|
||||
size_t max_size;
|
||||
bool shutdown = false;
|
||||
|
||||
public:
|
||||
/// @brief Creates a queue with fixed capacity.
|
||||
explicit WorkQueue(size_t capacity) : max_size(capacity) {}
|
||||
|
||||
/// @brief Pushes an item, blocking while full unless shutdown is signaled.
|
||||
bool push(T item) {
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
cv_not_full.wait(lock,
|
||||
[this] { return queue.size() < max_size || shutdown; });
|
||||
|
||||
if (shutdown)
|
||||
return false;
|
||||
|
||||
queue.push(std::move(item));
|
||||
cv_not_empty.notify_one();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @brief Pops an item, blocking while empty unless shutdown is signaled.
|
||||
std::optional<T> pop() {
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
cv_not_empty.wait(lock, [this] { return !queue.empty() || shutdown; });
|
||||
|
||||
if (queue.empty())
|
||||
return std::nullopt;
|
||||
|
||||
T item = std::move(queue.front());
|
||||
queue.pop();
|
||||
cv_not_full.notify_one();
|
||||
return item;
|
||||
}
|
||||
|
||||
/// @brief Signals queue shutdown and wakes all waiting producers/consumers.
|
||||
void shutdown_queue() {
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
shutdown = true;
|
||||
cv_not_empty.notify_all();
|
||||
cv_not_full.notify_all();
|
||||
}
|
||||
|
||||
/// @brief Returns current queue size.
|
||||
size_t size() const {
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
return queue.size();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user