| 19 | using caps_analyze_fn = std::function<void(bool, value &, value &)>; |
| 20 | |
| 21 | static void caps_try_execute(jinja::program & prog, |
| 22 | const caps_json_fn & messages_fn, |
| 23 | const caps_json_fn & tools_fn, |
| 24 | const caps_analyze_fn & analyze_fn) { |
| 25 | context ctx; |
| 26 | ctx.is_get_stats = true; |
| 27 | jinja::global_from_json(ctx, json{ |
| 28 | {"messages", messages_fn()}, |
| 29 | {"tools", tools_fn()}, |
| 30 | {"bos_token", ""}, |
| 31 | {"eos_token", ""}, |
| 32 | {"add_generation_prompt", true} |
| 33 | }, true); |
| 34 | |
| 35 | auto messages = ctx.get_val("messages"); |
| 36 | auto tools = ctx.get_val("tools"); |
| 37 | |
| 38 | bool success = false; |
| 39 | try { |
| 40 | jinja::runtime runtime(ctx); |
| 41 | runtime.execute(prog); |
| 42 | success = true; |
| 43 | } catch (const std::exception & e) { |
| 44 | JJ_DEBUG("Exception during execution: %s", e.what()); |
| 45 | // ignore exceptions during capability analysis |
| 46 | } |
| 47 | |
| 48 | analyze_fn(success, messages, tools); |
| 49 | } |
| 50 | |
| 51 | // for debugging only |
| 52 | static void caps_print_stats(value & v, const std::string & path) { |
no test coverage detected