@@ -20,11 +20,65 @@ public static String render(OutputFormatSpec spec, PromptOverrides overrides) {
2020 return switch (effectiveStyle ) {
2121 case EXAMPLE_ONLY -> renderExampleOnly (spec , overrides );
2222 case GUIDE -> renderGuide (spec , overrides );
23- case INLINE -> throw new UnsupportedOperationException (
24- "Style not yet implemented: " + effectiveStyle );
23+ case INLINE -> renderInline (spec , overrides );
2524 };
2625 }
2726
27+ private static String renderInline (OutputFormatSpec spec , PromptOverrides overrides ) {
28+ return switch (spec .format ()) {
29+ case XML -> renderXmlInline (spec , overrides );
30+ case JSON -> renderJsonInline (spec , overrides );
31+ };
32+ }
33+
34+ private static String renderXmlInline (OutputFormatSpec spec , PromptOverrides overrides ) {
35+ StringBuilder sb = new StringBuilder ();
36+ sb .append ("<" ).append (spec .rootName ()).append (">\n " );
37+ for (PromptField field : spec .fields ()) {
38+ String content = inlineContent (field , overrides );
39+ String escaped = Escapers .escape (Escapers .FORMAT_XML , content );
40+ sb .append (" <" ).append (field .name ()).append (">" )
41+ .append (escaped )
42+ .append ("</" ).append (field .name ()).append (">\n " );
43+ }
44+ sb .append ("</" ).append (spec .rootName ()).append (">" );
45+ return sb .toString ();
46+ }
47+
48+ private static String renderJsonInline (OutputFormatSpec spec , PromptOverrides overrides ) {
49+ StringBuilder sb = new StringBuilder ();
50+ sb .append ("{\n " );
51+ List <PromptField > fields = spec .fields ();
52+ for (int i = 0 ; i < fields .size (); i ++) {
53+ PromptField field = fields .get (i );
54+ String content = inlineContent (field , overrides );
55+ boolean isLast = i == fields .size () - 1 ;
56+ sb .append (" \" " ).append (field .name ()).append ("\" : " );
57+ sb .append ("\" " ).append (Escapers .escape (Escapers .FORMAT_JSON , content )).append ("\" " );
58+ if (!isLast ) sb .append ("," );
59+ sb .append ("\n " );
60+ }
61+ sb .append ("}" );
62+ return sb .toString ();
63+ }
64+
65+ private static String inlineContent (PromptField field , PromptOverrides overrides ) {
66+ if (field .kind () == FieldKind .ENUM
67+ && field .enumValues () != null
68+ && !field .enumValues ().isEmpty ()) {
69+ return String .join (" | " , field .enumValues ());
70+ }
71+ if (field .kind () == FieldKind .BOOLEAN ) {
72+ return "true | false" ;
73+ }
74+ String instruction = overrides .instructions ().get (field .name ());
75+ if (instruction == null ) instruction = field .instruction ();
76+ if (instruction != null ) {
77+ return "{" + instruction + "}" ;
78+ }
79+ return "{" + field .name () + "}" ;
80+ }
81+
2882 private static String renderGuide (OutputFormatSpec spec , PromptOverrides overrides ) {
2983 StringBuilder sb = new StringBuilder ();
3084 sb .append ("Fill in each field as described below:\n " );
0 commit comments