20 public static class ToolSpecification {
21 private String functionName;
22 private String functionDescription;
23 private Map<String, PromptFuncDefinition.Property> properties;
28 @JsonIgnoreProperties(ignoreUnknown =
true)
29 public static class PromptFuncDefinition {
31 private PromptFuncSpec
function;
34 public static class PromptFuncSpec {
36 private String description;
37 private Parameters parameters;
41 public static class Parameters {
43 private Map<String, Property> properties;
44 private List<String> required;
49 public static class Property {
51 private String description;
53 @JsonInclude(JsonInclude.Include.NON_NULL)
54 private List<String> enumValues;
56 private boolean required;
60 public static class PropsBuilder {
61 private final Map<String, PromptFuncDefinition.Property> props =
new HashMap<>();
63 public PropsBuilder withProperty(String key, PromptFuncDefinition.Property property) {
64 props.put(key, property);
68 public Map<String, PromptFuncDefinition.Property> build() {
73 public static class PromptBuilder {
74 private final List<PromptFuncDefinition> tools =
new ArrayList<>();
76 private String promptText;
78 public String build()
throws JsonProcessingException {
79 return "[AVAILABLE_TOOLS] " +
Utils.
getObjectMapper().writeValueAsString(tools) +
"[/AVAILABLE_TOOLS][INST] " + promptText +
" [/INST]";
82 public PromptBuilder withPrompt(String prompt)
throws JsonProcessingException {
87 public PromptBuilder withToolSpecification(ToolSpecification spec) {
88 PromptFuncDefinition def =
new PromptFuncDefinition();
89 def.setType(
"function");
91 PromptFuncDefinition.PromptFuncSpec functionDetail =
new PromptFuncDefinition.
PromptFuncSpec();
92 functionDetail.setName(spec.getFunctionName());
93 functionDetail.setDescription(spec.getFunctionDescription());
95 PromptFuncDefinition.Parameters parameters =
new PromptFuncDefinition.Parameters();
96 parameters.setType(
"object");
97 parameters.setProperties(spec.getProperties());
99 List<String> requiredValues =
new ArrayList<>();
100 for (Map.Entry<String, PromptFuncDefinition.Property> p : spec.getProperties().entrySet()) {
101 if (p.getValue().isRequired()) {
102 requiredValues.add(p.getKey());
105 parameters.setRequired(requiredValues);
106 functionDetail.setParameters(parameters);
107 def.setFunction(functionDetail);