spring-projects / spring-projects/spring-ai
Optimization of thinking content acquisition in thinking models
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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