30 public static class Tool {
31 @JsonProperty(
"function")
32 private ToolSpec toolSpec;
34 @Builder.Default
private String type =
"function";
42 public static class ToolSpec {
44 private String description;
45 private Parameters parameters;
51 public static class Parameters {
52 private Map<String, Property> properties;
53 private List<String> required =
new ArrayList<>();
55 public static Parameters of(Map<String, Property> properties) {
56 Parameters params =
new Parameters();
57 params.setProperties(properties);
59 if (properties !=
null) {
60 for (Map.Entry<String, Property> entry : properties.entrySet()) {
61 if (entry.getValue() !=
null && entry.getValue().isRequired()) {
62 params.getRequired().add(entry.getKey());
70 public String toString() {
72 com.fasterxml.jackson.databind.json.JsonMapper.builder()
75 node.put(
"type",
"object");
76 if (properties !=
null) {
77 ObjectNode propsNode = node.putObject(
"properties");
78 for (Map.Entry<String, Property> entry : properties.entrySet()) {
79 ObjectNode propNode = propsNode.putObject(entry.getKey());
80 Property prop = entry.getValue();
81 propNode.put(
"type", prop.getType());
82 propNode.put(
"description", prop.getDescription());
83 if (prop.getEnumValues() !=
null) {
84 propNode.putArray(
"enum")
86 prop.getEnumValues().stream()
88 com.fasterxml.jackson.databind.node.TextNode
90 .collect(java.util.stream.Collectors.toList()));
94 if (required !=
null && !required.isEmpty()) {
95 node.putArray(
"required")
98 .map(com.fasterxml.jackson.databind.node.TextNode::new)
99 .collect(java.util.stream.Collectors.toList()));
101 return node.toPrettyString();
109 public static class Property {
111 private String description;
113 @JsonProperty(
"enum")
114 @JsonInclude(JsonInclude.Include.NON_NULL)
115 private List<String> enumValues;
117 @JsonIgnore
private boolean required;