Skip to content

Conversation

chang6666
Copy link

Resolved the exceptional issue of converting the large model deployed locally with Ollama into a Java Bean.

Resolved the exceptional issue of converting the large model deployed locally with Ollama into a Java Bean.

Signed-off-by: James <[email protected]>
@@ -159,6 +159,7 @@ private void generateSchema() {
@Override
public T convert(@NonNull String text) {
try {
text = text.replaceAll("<think>[\\s\\s]*?</think>","")
Copy link
Member

@markpollack markpollack Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are going to have to opt into this 'exclusion' in the output converter. I'd like to make this a pluggable stragtegy, who knows how many ways the thinking response will be done. is this from anthropic or deepseek?. we have to overhaul the whole code base to handle 'thinking' responses in the assistant messgae, but hacks like this are useful.

also missing semicolon

Copy link
Contributor

@YunKuiLu YunKuiLu Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be \s and \S here?

Suggested change
text = text.replaceAll("<think>[\\s\\s]*?</think>","")
text = text.replaceAll("<think>[\\s\\S]*?</think>","");

Although this regex is simple, it's better to have unit tests.

Copy link
Contributor

@nicolaskrier nicolaskrier Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented something similar for qwen3:14b model running locally on my Ollama. The solution is a bit more complex but it works properly until now.

@Override
public T convert(@NonNull String text) {
    var thinkingPattern = Pattern.compile("^<think>[\\w\\s\\p{P}]*</think>", Pattern.MULTILINE);
    var thinkingMatcher = thinkingPattern.matcher(text);
    var cleanedText = thinkingMatcher.replaceFirst("");

    return super.convert(cleanedText);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants