Quick vibe-coded fix for proper object printing
This commit is contained in:
parent
ad74de7548
commit
08c403efcd
|
|
@ -192,6 +192,7 @@ std::optional<compare_variants_result> differential_analyzer::compare_variants(
|
|||
if (params_modifier) {
|
||||
params_modifier(params_B);
|
||||
}
|
||||
|
||||
|
||||
// Apply template to both variants
|
||||
std::string output_A = apply_template(tmpl, params_A);
|
||||
|
|
@ -683,7 +684,8 @@ void differential_analyzer::analyze_tool_call_format_json_native(const std::stri
|
|||
// we might not have the typical OpenAI tool calling structure
|
||||
int json_start = clean_haystack.find_first_of('{');
|
||||
int json_end = clean_haystack.find_last_of('}');
|
||||
json call_struct = json::parse(clean_haystack.substr(json_start, json_end - json_start + 1));
|
||||
std::string cut = clean_haystack.substr(json_start, json_end - json_start + 1);
|
||||
json call_struct = json::parse(cut);
|
||||
auto register_field = [&](const std::string & prefix,
|
||||
const nlohmann::detail::iteration_proxy_value<json::iterator> & subel) {
|
||||
if (subel.value().is_string() && std::string(subel.value()).find("call0000") != std::string::npos) {
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ json common_chat_msg::to_json_oaicompat(bool concat_typed_text) const {
|
|||
{"type", "function"},
|
||||
{"function", {
|
||||
{"name", tool_call.name},
|
||||
{"arguments", tool_call.arguments},
|
||||
{"arguments", json::parse(tool_call.arguments)},
|
||||
}},
|
||||
};
|
||||
if (!tool_call.id.empty()) {
|
||||
|
|
|
|||
|
|
@ -502,12 +502,21 @@ struct value_object_t : public value_t {
|
|||
virtual bool is_immutable() const override { return false; }
|
||||
virtual const std::vector<std::pair<value, value>> & as_ordered_object() const override { return val_obj; }
|
||||
virtual string as_string() const override {
|
||||
// Use JSON format for object string representation to ensure compatibility
|
||||
// when concatenated in templates (e.g., '{"name": ' + arguments + '}')
|
||||
std::ostringstream ss;
|
||||
ss << "{";
|
||||
for (size_t i = 0; i < val_obj.size(); i++) {
|
||||
if (i > 0) ss << ", ";
|
||||
auto & [key, val] = val_obj.at(i);
|
||||
ss << value_to_string_repr(key) << ": " << value_to_string_repr(val);
|
||||
// Use double quotes for keys (JSON format)
|
||||
ss << "\"" << key->as_string().str() << "\": ";
|
||||
if (is_val<value_string>(val)) {
|
||||
// Strings need to be quoted in JSON
|
||||
ss << "\"" << val->as_string().str() << "\"";
|
||||
} else {
|
||||
ss << val->as_string().str();
|
||||
}
|
||||
}
|
||||
ss << "}";
|
||||
return ss.str();
|
||||
|
|
|
|||
|
|
@ -973,7 +973,6 @@ static void test_msgs_oaicompat_json_conversion() {
|
|||
common_chat_msgs_to_json_oaicompat({ message_user_parts }).dump(2));
|
||||
|
||||
// Note: content is "" instead of null due to workaround for templates that render null as "None"
|
||||
// Arguments are serialized as string for OAI compatibility
|
||||
assert_equals(std::string("[\n"
|
||||
" {\n"
|
||||
" \"role\": \"assistant\",\n"
|
||||
|
|
@ -983,7 +982,9 @@ static void test_msgs_oaicompat_json_conversion() {
|
|||
" \"type\": \"function\",\n"
|
||||
" \"function\": {\n"
|
||||
" \"name\": \"python\",\n"
|
||||
" \"arguments\": \"{\\\"code\\\":\\\"print('hey')\\\"}\"\n"
|
||||
" \"arguments\": {\n"
|
||||
" \"code\": \"print('hey')\"\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
|
|
|
|||
Loading…
Reference in New Issue