Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions engine/utils/cli_selection_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <optional>
#include <string>
#include <vector>
#include "utils/logging_utils.h"
#include "utils/string_utils.h"

namespace cli_selection_utils {
const std::string indent = std::string(4, ' ');
Expand All @@ -13,7 +13,8 @@ inline void PrintMenu(
auto index{start_index};
for (const auto& option : options) {
bool is_default = false;
if (default_option.has_value() && option == default_option.value()) {
if (default_option.has_value() &&
string_utils::EqualsIgnoreCase(option, default_option.value())) {
is_default = true;
}
std::string selection{std::to_string(index) + ". " + option +
Expand Down Expand Up @@ -48,10 +49,13 @@ inline std::optional<std::string> PrintModelSelection(

// if selection is empty and default selection is inside availables, return default_selection
if (selection.empty()) {
if (default_selection.has_value() &&
std::find(availables.begin(), availables.end(),
default_selection.value()) != availables.end()) {
return default_selection;
if (default_selection.has_value()) {
for (const auto& available : availables) {
if (string_utils::EqualsIgnoreCase(available,
default_selection.value())) {
return available;
}
}
}
return std::nullopt;
}
Expand Down
5 changes: 5 additions & 0 deletions engine/utils/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ struct ParsePromptResult {
std::string ai_prompt;
};

inline bool EqualsIgnoreCase(const std::string& a, const std::string& b) {
return std::equal(a.begin(), a.end(), b.begin(), b.end(),
[](char a, char b) { return tolower(a) == tolower(b); });
}

inline ParsePromptResult ParsePrompt(const std::string& prompt) {
auto& pt = prompt;
ParsePromptResult result;
Expand Down
Loading