Package org.springframework.ai.converter
Class ThinkingTagCleaner
java.lang.Object
org.springframework.ai.converter.ThinkingTagCleaner
- All Implemented Interfaces:
ResponseTextCleaner
A
ResponseTextCleaner that removes thinking tags from LLM responses. This
cleaner supports multiple tag patterns to handle different AI models:
- Amazon Nova:
<thinking>...</thinking> - Qwen models:
<think>...</think> - DeepSeek models: various thinking patterns
- Claude models: thinking blocks in different formats
Performance: This cleaner includes fast-path optimization. For responses without thinking tags (most models), it performs a quick character check and returns immediately, making it safe to use as a default cleaner even for non-thinking models.
- Since:
- 1.1.0
- Author:
- liugddx
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreates a cleaner with default thinking tag patterns.ThinkingTagCleaner(String... patternStrings) Creates a cleaner with custom pattern strings.ThinkingTagCleaner(List<Pattern> patterns) Creates a cleaner with custom patterns. -
Method Summary
Modifier and TypeMethodDescriptionstatic ThinkingTagCleaner.Builderbuilder()Creates a builder for constructing a thinking tag cleaner.Clean the given text by removing unwanted patterns, tags, or formatting.
-
Constructor Details
-
ThinkingTagCleaner
public ThinkingTagCleaner()Creates a cleaner with default thinking tag patterns. -
ThinkingTagCleaner
Creates a cleaner with custom patterns.- Parameters:
patterns- the list of regex patterns to match thinking tags
-
ThinkingTagCleaner
Creates a cleaner with custom pattern strings.- Parameters:
patternStrings- the list of regex pattern strings to match thinking tags
-
-
Method Details
-
clean
Description copied from interface:ResponseTextCleanerClean the given text by removing unwanted patterns, tags, or formatting.- Specified by:
cleanin interfaceResponseTextCleaner- Parameters:
text- the raw text from LLM response- Returns:
- the cleaned text ready for parsing
-
builder
Creates a builder for constructing a thinking tag cleaner.- Returns:
- a new builder instance
-