Skip to content

Commit b8d9765

Browse files
committed
Clean up Thinking Block from json-markup
1 parent e2bdf4b commit b8d9765

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

embabel-common-core/src/main/kotlin/com/embabel/common/core/thinking/spi/thinkingBlocksExtraction.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fun extractAllThinkingBlocks(input: String): List<ThinkingBlock> {
108108
// Extract remaining content before JSON
109109
val noPrefixPattern = "^(.*?)(?=\\{)".toRegex(RegexOption.DOT_MATCHES_ALL)
110110
noPrefixPattern.find(remainingInput.trim())?.let { match ->
111-
val content = match.groupValues[1].trim()
111+
val content = skipMarkdownArtifacts(match.groupValues[1].trim())
112112
if (content.isNotEmpty()) {
113113
blocks.add(
114114
ThinkingBlock(
@@ -122,3 +122,14 @@ fun extractAllThinkingBlocks(input: String): List<ThinkingBlock> {
122122

123123
return blocks.sortedBy { input.indexOf(it.content) }
124124
}
125+
126+
/**
127+
* Remove markdown artifacts that should not be considered thinking content.
128+
* Currently handles ```json code fence markers that commonly appear before JSON output,
129+
* see get format in [[JacksonConverter]]
130+
*/
131+
private fun skipMarkdownArtifacts(content: String): String {
132+
return content
133+
.replace("```json", "")
134+
.trim()
135+
}

0 commit comments

Comments
 (0)