Skip to content
Open
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
18 changes: 1 addition & 17 deletions cactus-engine/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1699,23 +1699,7 @@ inline InferenceOptions parse_inference_options_json(const std::string& json) {
options.enable_thinking_if_supported = (json.substr(pos, 4) == "true");
}

pos = json.find("\"stop_sequences\"");
if (pos != std::string::npos) {
pos = json.find('[', pos);
if (pos != std::string::npos) {
size_t end_pos = json.find(']', pos);
size_t seq_pos = json.find('"', pos);

while (seq_pos != std::string::npos && seq_pos < end_pos) {
size_t seq_start = seq_pos + 1;
size_t seq_end = json.find('"', seq_start);
if (seq_end != std::string::npos) {
options.stop_sequences.push_back(json.substr(seq_start, seq_end - seq_start));
}
seq_pos = json.find('"', seq_end + 1);
}
}
}
options.stop_sequences = parse_json_string_array_field(json, "stop_sequences");

return options;
}
Expand Down
23 changes: 23 additions & 0 deletions cactus-engine/tests/test_inference_options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "test_utils.h"
#include "../src/utils.h"

using cactus::ffi::parse_inference_options_json;

bool test_stop_sequences_decode_json_escapes() {
auto options = parse_inference_options_json(
R"({"stop_sequences": ["\n\n", "C:\\", "caf\u00e9", "\"\""], "max_tokens": 64})");
return options.stop_sequences == std::vector<std::string>{"\n\n", "C:\\", "caf\xc3\xa9", "\"\""};
}

bool test_stop_sequence_with_quote_as_last_option() {
auto options = parse_inference_options_json(R"({"max_tokens": 64, "stop_sequences": ["\""]})");
return options.stop_sequences == std::vector<std::string>{"\""};
}

int main() {
TestUtils::TestRunner runner("Inference Options Tests");
runner.run_test("stop_sequences_decode_json_escapes", test_stop_sequences_decode_json_escapes());
runner.run_test("stop_sequence_with_quote_as_last_option", test_stop_sequence_with_quote_as_last_option());
runner.print_summary();
return runner.all_passed() ? 0 : 1;
}