|
61 | 61 | */
|
62 | 62 | public class BeanOutputConverter<T> implements StructuredOutputConverter<T> {
|
63 | 63 |
|
64 |
| - private final Logger logger = LoggerFactory.getLogger(BeanOutputConverter.class); |
| 64 | + protected final Logger logger = LoggerFactory.getLogger(BeanOutputConverter.class); |
65 | 65 |
|
66 | 66 | /**
|
67 | 67 | * The target class type reference to which the output will be converted.
|
68 | 68 | */
|
69 |
| - private final Type type; |
| 69 | + protected final Type type; |
70 | 70 |
|
71 | 71 | /** The object mapper used for deserialization and other JSON operations. */
|
72 | 72 | private final ObjectMapper objectMapper;
|
73 | 73 |
|
74 | 74 | /** Holds the generated JSON schema for the target type. */
|
75 |
| - private String jsonSchema; |
| 75 | + protected String jsonSchema; |
76 | 76 |
|
77 | 77 | /**
|
78 | 78 | * Constructor to initialize with the target type's class.
|
@@ -128,7 +128,7 @@ private BeanOutputConverter(Type type, ObjectMapper objectMapper) {
|
128 | 128 | /**
|
129 | 129 | * Generates the JSON schema for the target type.
|
130 | 130 | */
|
131 |
| - private void generateSchema() { |
| 131 | + protected void generateSchema() { |
132 | 132 | JacksonModule jacksonModule = new JacksonModule(JacksonOption.RESPECT_JSONPROPERTY_REQUIRED,
|
133 | 133 | JacksonOption.RESPECT_JSONPROPERTY_ORDER);
|
134 | 134 | SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(
|
@@ -206,15 +206,23 @@ protected ObjectMapper getObjectMapper() {
|
206 | 206 | */
|
207 | 207 | @Override
|
208 | 208 | public String getFormat() {
|
209 |
| - String template = """ |
| 209 | + return String.format(getFormatTemplate(), this.jsonSchema); |
| 210 | + } |
| 211 | + |
| 212 | + /** |
| 213 | + * Provides the template for the format instruction. Subclasses can override this |
| 214 | + * method to customize the instruction format. |
| 215 | + * @return The format template string. |
| 216 | + */ |
| 217 | + protected String getFormatTemplate() { |
| 218 | + return """ |
210 | 219 | Your response should be in JSON format.
|
211 | 220 | Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation.
|
212 | 221 | Do not include markdown code blocks in your response.
|
213 | 222 | Remove the ```json markdown from the output.
|
214 | 223 | Here is the JSON Schema instance your output must adhere to:
|
215 | 224 | ```%s```
|
216 | 225 | """;
|
217 |
| - return String.format(template, this.jsonSchema); |
218 | 226 | }
|
219 | 227 |
|
220 | 228 | /**
|
|
0 commit comments