11package com .theokanning .openai .response .tool .definition ;
22
3+ import com .fasterxml .jackson .annotation .JsonInclude ;
4+ import com .fasterxml .jackson .annotation .JsonSubTypes ;
5+ import com .fasterxml .jackson .annotation .JsonTypeInfo ;
6+ import com .theokanning .openai .assistants .assistant .Tool ;
37import lombok .AllArgsConstructor ;
48import lombok .Builder ;
59import lombok .Data ;
@@ -34,13 +38,33 @@ public class CustomTool implements ToolDefinition {
3438 /**
3539 * Input format specification.
3640 */
37- private Object format ; // TextFormat or GrammarFormat
41+ private Format format ; // TextFormat or GrammarFormat
42+
43+
44+ @ JsonTypeInfo (
45+ use = JsonTypeInfo .Id .NAME ,
46+ include = JsonTypeInfo .As .EXISTING_PROPERTY ,
47+ property = "type"
48+ )
49+ @ JsonSubTypes ({
50+ @ JsonSubTypes .Type (value = TextFormat .class , name = "text" ),
51+ @ JsonSubTypes .Type (value = GrammarFormat .class , name = "grammar" ),
52+ })
53+ @ JsonInclude (JsonInclude .Include .NON_NULL )
54+ public interface Format {
55+
56+ /**
57+ * Get the tool type.
58+ */
59+ String getType ();
60+ }
61+
3862
3963 @ Data
4064 @ Builder
4165 @ NoArgsConstructor
4266 @ AllArgsConstructor
43- public static class TextFormat {
67+ public static class TextFormat implements Format {
4468
4569 /**
4670 * Format type, always "text".
@@ -52,7 +76,7 @@ public static class TextFormat {
5276 @ Builder
5377 @ NoArgsConstructor
5478 @ AllArgsConstructor
55- public static class GrammarFormat {
79+ public static class GrammarFormat implements Format {
5680
5781 /**
5882 * Format type, always "grammar".
@@ -69,4 +93,9 @@ public static class GrammarFormat {
6993 */
7094 private String definition ;
7195 }
96+
97+ @ Override
98+ public Tool getRealTool () {
99+ return new Tool .Custom (this );
100+ }
72101}
0 commit comments