File tree Expand file tree Collapse file tree
embabel-common-core/src/main/kotlin/com/embabel/common/core/thinking/spi Expand file tree Collapse file tree Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments