Find parameter schema properties for a function.
| 53 | // Check if a function name is in the allowed tools list. |
| 54 | static bool tool_allowed(const json & tools, const std::string & name) { |
| 55 | if (tools.is_null() || !tools.is_array() || tools.empty()) return true; |
| 56 | for (const auto & t : tools) { |
| 57 | const auto & fn = t.contains("function") ? t["function"] : t; |
| 58 | if (fn.is_object() && fn.value("name", "") == name) return true; |
| 59 | } |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | // Find parameter schema properties for a function. |
| 64 | static json find_tool_properties(const json & tools, const std::string & name) { |
| 65 | if (tools.is_null() || !tools.is_array()) return json::object(); |
| 66 | for (const auto & t : tools) { |
| 67 | const auto & fn = t.contains("function") ? t["function"] : t; |
| 68 | if (!fn.is_object() || fn.value("name", "") != name) continue; |
| 69 | if (fn.contains("parameters") && fn["parameters"].is_object()) { |
| 70 | const auto & params = fn["parameters"]; |
| 71 | if (params.contains("properties") && params["properties"].is_object()) { |