spring-projects / spring-projects/spring-ai

Optimization of thinking content acquisition in thinking models

Open
#4,269 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 10h
Merged PRs (30d)
5

Description

Spring AI's retrieval of reasoning content from deep-thinking model responses is overly cumbersome. Can you provide a unified solution for obtaining reasoning content?

Currently, processing thinking content is very cumbersome, as follows:
`
AtomicBoolean atomicBoolean = new AtomicBoolean(false);
clientRequestSpec
.stream()
.chatResponse()
.doOnNext(response -> {
AssistantMessage output = response.getResult().getOutput();
String text = output.getText();
if(StringUtils.hasText(text)){
atomicBoolean.set(true);
}
boolean noThink = atomicBoolean.get();
if(!noThink){
String reasoningContent ;
if(output instanceof DeepSeekAssistantMessage deepSeekAssistantMessage){
reasoningContent = deepSeekAssistantMessage.getReasoningContent();
}else{
Map<String, Object> metadata = output.getMetadata();
Object o = metadata.get("reasoningContent");
reasoningContent = o != null ? o.toString() : "";
}

                }
              
            })
            .doOnError(error->{
                String errorMsg = error.getMessage();
            })
            .doOnComplete(() -> {})
            .subscribe();`

In LangChain4j, a dedicated interface for acquiring thinking content is provided, which is very convenient, as follows:
`public interface TokenStream {

TokenStream onPartialResponse(Consumer<String> partialResponseHandler);

/**
 * The provided consumer will be invoked every time a new partial thinking/reasoning text (usually a single token)
 * from a language model is available.
 */
default TokenStream onPartialThinking(Consumer<PartialThinking> partialThinkingHandler) {
    throw new UnsupportedOperationException("not implemented");
}

TokenStream onCompleteResponse(Consumer<ChatResponse> completeResponseHandler);


TokenStream onError(Consumer<Throwable> errorHandler);

}
`

I hope to get your help. thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing clientRequestSpec.stream().chatResponse() and how AssistantMessage, DeepSeekAssistantMessage, and response metadata currently expose reasoning content. Compare this flow with the cited LangChain4j TokenStream callbacks; done should mean a documented, consistent way to obtain thinking content across supported model responses.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
ai, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.