@@ -964,61 +964,45 @@ public record CompleteCompletion(// @formatter:off
964964 @ JsonSubTypes .Type (value = EmbeddedResource .class , name = "resource" ) })
965965 public sealed interface Content permits TextContent , ImageContent , EmbeddedResource {
966966
967- String type ();
967+ default String type () {
968+ if (this instanceof TextContent ) {
969+ return "text" ;
970+ }
971+ else if (this instanceof ImageContent ) {
972+ return "image" ;
973+ }
974+ else if (this instanceof EmbeddedResource ) {
975+ return "resource" ;
976+ }
977+ throw new IllegalArgumentException ("Unknown content type: " + this );
978+ }
968979
969980 }
970981
971982 @ JsonInclude (JsonInclude .Include .NON_ABSENT )
972983 public record TextContent ( // @formatter:off
973984 @ JsonProperty ("audience" ) List <Role > audience ,
974985 @ JsonProperty ("priority" ) Double priority ,
975- @ JsonProperty ("type" ) String type ,
976986 @ JsonProperty ("text" ) String text ) implements Content { // @formatter:on
977987
978- public TextContent {
979- type = "text" ;
980- }
981-
982- public String type () {
983- return type ;
984- }
985-
986988 public TextContent (String content ) {
987- this (null , null , "text" , content );
989+ this (null , null , content );
988990 }
989991 }
990992
991993 @ JsonInclude (JsonInclude .Include .NON_ABSENT )
992994 public record ImageContent ( // @formatter:off
993995 @ JsonProperty ("audience" ) List <Role > audience ,
994996 @ JsonProperty ("priority" ) Double priority ,
995- @ JsonProperty ("type" ) String type ,
996997 @ JsonProperty ("data" ) String data ,
997998 @ JsonProperty ("mimeType" ) String mimeType ) implements Content { // @formatter:on
998-
999- public ImageContent {
1000- type = "image" ;
1001- }
1002-
1003- public String type () {
1004- return type ;
1005- }
1006999 }
10071000
10081001 @ JsonInclude (JsonInclude .Include .NON_ABSENT )
10091002 public record EmbeddedResource ( // @formatter:off
10101003 @ JsonProperty ("audience" ) List <Role > audience ,
10111004 @ JsonProperty ("priority" ) Double priority ,
1012- @ JsonProperty ("type" ) String type ,
10131005 @ JsonProperty ("resource" ) ResourceContents resource ) implements Content { // @formatter:on
1014-
1015- public EmbeddedResource {
1016- type = "resource" ;
1017- }
1018-
1019- public String type () {
1020- return type ;
1021- }
10221006 }
10231007
10241008 // ---------------------------
0 commit comments