Quick vibe-coded fix for proper object printing
This commit is contained in:
parent
a4feadb10d
commit
2eedbb24e0
|
|
@ -192,6 +192,7 @@ std::optional<compare_variants_result> differential_analyzer::compare_variants(
|
||||||
if (params_modifier) {
|
if (params_modifier) {
|
||||||
params_modifier(params_B);
|
params_modifier(params_B);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Apply template to both variants
|
// Apply template to both variants
|
||||||
std::string output_A = apply_template(tmpl, params_A);
|
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
|
// we might not have the typical OpenAI tool calling structure
|
||||||
int json_start = clean_haystack.find_first_of('{');
|
int json_start = clean_haystack.find_first_of('{');
|
||||||
int json_end = clean_haystack.find_last_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,
|
auto register_field = [&](const std::string & prefix,
|
||||||
const nlohmann::detail::iteration_proxy_value<json::iterator> & subel) {
|
const nlohmann::detail::iteration_proxy_value<json::iterator> & subel) {
|
||||||
if (subel.value().is_string() && std::string(subel.value()).find("call0000") != std::string::npos) {
|
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"},
|
{"type", "function"},
|
||||||
{"function", {
|
{"function", {
|
||||||
{"name", tool_call.name},
|
{"name", tool_call.name},
|
||||||
{"arguments", tool_call.arguments},
|
{"arguments", json::parse(tool_call.arguments)},
|
||||||
}},
|
}},
|
||||||
};
|
};
|
||||||
if (!tool_call.id.empty()) {
|
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 bool is_immutable() const override { return false; }
|
||||||
virtual const std::vector<std::pair<value, value>> & as_ordered_object() const override { return val_obj; }
|
virtual const std::vector<std::pair<value, value>> & as_ordered_object() const override { return val_obj; }
|
||||||
virtual string as_string() const override {
|
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;
|
std::ostringstream ss;
|
||||||
ss << "{";
|
ss << "{";
|
||||||
for (size_t i = 0; i < val_obj.size(); i++) {
|
for (size_t i = 0; i < val_obj.size(); i++) {
|
||||||
if (i > 0) ss << ", ";
|
if (i > 0) ss << ", ";
|
||||||
auto & [key, val] = val_obj.at(i);
|
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 << "}";
|
ss << "}";
|
||||||
return ss.str();
|
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));
|
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"
|
// 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"
|
assert_equals(std::string("[\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
" \"role\": \"assistant\",\n"
|
" \"role\": \"assistant\",\n"
|
||||||
|
|
@ -983,7 +982,9 @@ static void test_msgs_oaicompat_json_conversion() {
|
||||||
" \"type\": \"function\",\n"
|
" \"type\": \"function\",\n"
|
||||||
" \"function\": {\n"
|
" \"function\": {\n"
|
||||||
" \"name\": \"python\",\n"
|
" \"name\": \"python\",\n"
|
||||||
" \"arguments\": \"{\\\"code\\\":\\\"print('hey')\\\"}\"\n"
|
" \"arguments\": {\n"
|
||||||
|
" \"code\": \"print('hey')\"\n"
|
||||||
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" ]\n"
|
" ]\n"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue