Skip to content

Commit

Permalink
Extend format to improve generate JSON
Browse files Browse the repository at this point in the history
- Add an additional instruction to the format for the model not to include markdown syntax for JSON quotes.
- Extend the conversion to strip markdown quotes in case the model included them in the response
  • Loading branch information
pgerhard committed May 29, 2024
1 parent ac91302 commit 2cda983
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public MapOutputConverter() {

@Override
public Map<String, Object> convert(@NonNull String text) {
if (text.startsWith("```json") && text.endsWith("```")) {
text = text.substring(7, text.length() - 3);
}

Message<?> message = MessageBuilder.withPayload(text.getBytes(StandardCharsets.UTF_8)).build();
return (Map) this.getMessageConverter().fromMessage(message, HashMap.class);
}
Expand All @@ -50,7 +54,8 @@ public String getFormat() {
Your response should be in JSON format.
The data structure for the JSON should match this Java class: %s
Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation.
""";
Remove the ```json markdown from the output.
""";
return String.format(raw, HashMap.class.getName());
}

Expand Down

0 comments on commit 2cda983

Please sign in to comment.