22 public static class ToolSpecification {
23 private String functionName;
24 private String functionDescription;
25 private PromptFuncDefinition toolPrompt;
30 @JsonIgnoreProperties(ignoreUnknown =
true)
34 public static class PromptFuncDefinition {
36 private PromptFuncSpec
function;
42 public static class PromptFuncSpec {
44 private String description;
45 private Parameters parameters;
52 public static class Parameters {
54 private Map<String, Property> properties;
55 private List<String> required;
62 public static class Property {
64 private String description;
66 @JsonInclude(JsonInclude.Include.NON_NULL)
67 private List<String> enumValues;
69 private boolean required;
73 public static class PropsBuilder {
74 private final Map<String, PromptFuncDefinition.Property> props =
new HashMap<>();
76 public PropsBuilder withProperty(String key, PromptFuncDefinition.Property property) {
77 props.put(key, property);
81 public Map<String, PromptFuncDefinition.Property> build() {
86 public static class PromptBuilder {
87 private final List<PromptFuncDefinition>
tools =
new ArrayList<>();
89 private String promptText;
91 public String build()
throws JsonProcessingException {
92 return "[AVAILABLE_TOOLS] " +
Utils.
getObjectMapper().writeValueAsString(
tools) +
"[/AVAILABLE_TOOLS][INST] " + promptText +
" [/INST]";
95 public PromptBuilder withPrompt(String prompt)
throws JsonProcessingException {
100 public PromptBuilder withToolSpecification(ToolSpecification spec) {
101 PromptFuncDefinition def =
new PromptFuncDefinition();
102 def.setType(
"function");
104 PromptFuncDefinition.PromptFuncSpec functionDetail =
new PromptFuncDefinition.
PromptFuncSpec();
105 functionDetail.setName(spec.getFunctionName());
106 functionDetail.setDescription(spec.getFunctionDescription());
108 PromptFuncDefinition.Parameters parameters =
new PromptFuncDefinition.Parameters();
109 parameters.setType(
"object");
110 parameters.setProperties(spec.getToolPrompt().getFunction().parameters.getProperties());
112 List<String> requiredValues =
new ArrayList<>();
113 for (Map.Entry<String, PromptFuncDefinition.Property> p : spec.getToolPrompt().getFunction().getParameters().getProperties().entrySet()) {
114 if (p.getValue().isRequired()) {
115 requiredValues.add(p.getKey());
118 parameters.setRequired(requiredValues);
119 functionDetail.setParameters(parameters);
120 def.setFunction(functionDetail);