Model Picker — C++ source
Filter every major model by context window, price, modality, and tier — sort by cost, context, or tokens-per-dollar to find the right model for the task.
This is the C++ implementation — the same logic the interactive tool runs, in a shareable, citable form.
// model-picker — C++ port: filter + rank the AI model catalog.
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <optional>
#include <string>
#include <vector>
// Pricing projection of the TS AiModel record; optionals play TS null.
struct Model {
std::string id, tier;
long long context_window; // context window in tokens.
std::optional<double> input_per_m; // USD per 1M input tokens.
std::optional<double> output_per_m; // USD per 1M output tokens.
};
// Projection of the TS ModelFilter — the three constraints the presets use;
// null prices never satisfy max_input_per_m.
struct ModelFilter {
std::optional<std::string> tier;
std::optional<long long> min_context;
std::optional<double> max_input_per_m;
};
// Sort keys: the TS SortKey union (tokensPerDollar and released follow the
// same pattern — rank 1e6 / output_per_m, or the date, descending).
enum class SortKey { price, context };
// Rank core: value order (desc when asked), null last, id asc on ties.
// std::optional plays the TS null field; it sorts after every real value.
template <typename T>
bool rank(const Model &a, const Model &b, bool desc, std::optional<T> ka, std::optional<T> kb) {
if (!ka && !kb) return a.id < b.id;
if (!ka) return false;
if (!kb) return true;
if (*ka == *kb) return a.id < b.id;
return desc ? *kb < *ka : *ka < *kb;
}
// Strict "a before b" per key — the TS COMPARATORS map; every comparator
// fully orders, so std::sort (unstable) stays deterministic.
bool less_than(SortKey key, const Model &a, const Model &b) {
if (key == SortKey::price) return rank(a, b, false, a.input_per_m, b.input_per_m);
return rank(a, b, true, std::optional<long long>{a.context_window},
std::optional<long long>{b.context_window});
}
// Filter step, inlined from listModels in src/lib/ai/models.ts.
std::vector<Model> list_models(std::vector<Model> models, const ModelFilter &f) {
std::erase_if(models, [&](const Model &m) {
return (f.tier && m.tier != *f.tier) ||
(f.min_context && m.context_window < *f.min_context) ||
(f.max_input_per_m &&
(!m.input_per_m || *m.input_per_m > *f.max_input_per_m));
});
return models;
}
// Filter the model list, then sort it. See less_than for the exact order.
std::vector<Model> pick_models(std::vector<Model> models, const ModelFilter &f, SortKey key) {
std::vector<Model> rows = list_models(std::move(models), f);
std::sort(rows.begin(), rows.end(),
[&](const Model &a, const Model &b) { return less_than(key, a, b); });
return rows;
}
int main() {
// Rates flow from the model snapshot; one row is unpriced.
std::vector<Model> models = {
{"atlas-flagship", "flagship", 1'000'000, 3.0, 15.0},
{"atlas-mini", "fast", 200'000, 0.5, 2.0},
{"nova-open", "balanced", 1'000'000, std::nullopt, std::nullopt},
{"zeta-budget", "budget", 128'000, 0.5, 1.0},
};
std::cout << "long-context (minContext >= 500000, sort context):\n";
for (const Model &m :
pick_models(models, ModelFilter{.min_context = 500'000}, SortKey::context))
std::cout << " " << std::left << std::setw(14) << m.id << "ctx " << m.context_window << '\n';
std::cout << "price sort (all models, unpriced last, ties by id):\n";
for (const Model &m : pick_models(models, ModelFilter{}, SortKey::price)) {
std::cout << " " << std::left << std::setw(14) << m.id;
if (m.input_per_m) std::cout << '$' << *m.input_per_m << "/M in\n";
else std::cout << "unpriced\n";
}
}
Also available in 13 other languages
Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in a dozen-plus languages — the same contract, ported. Compare all languages side by side →