spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

How can I get the thinking content using a thinking model?

Open Conanxy opened this issue 1 year ago • 5 comments

When I use AzureOpenAI or OpenAI, how do I get the thinking content using a thinking model?

There is no relevant description in the springAI documentation。but when i use deepseek,i can get it:

    List<Message> messages = new ArrayList<>();
    messages.add(new UserMessage("9.11 and 9.8, which is greater?"));
    DeepSeekChatOptions promptOptions = DeepSeekChatOptions.builder()
            .model(DeepSeekApi.ChatModel.DEEPSEEK_REASONER.getValue())
            .build();

    Prompt prompt = new Prompt(messages, promptOptions);
    ChatResponse response = chatModel.call(prompt);

    DeepSeekAssistantMessage deepSeekAssistantMessage = (DeepSeekAssistantMessage) response.getResult().getOutput();
    String reasoningContent = deepSeekAssistantMessage.getReasoningContent();
    String text = deepSeekAssistantMessage.getText();

Conanxy avatar Jul 31 '25 15:07 Conanxy

At present, there seems to be no way but to add fields to receive responses.

Image Image

cKnight107 avatar Aug 01 '25 13:08 cKnight107

As far as I know, support for "thinking" is already in progress, and consideration is being given to how to support "thinking" in the model as a whole.

sunyuhan1998 avatar Aug 04 '25 01:08 sunyuhan1998

My suggestion is to introduce a new field in AssistantMessage and handle it the same as the toolCalls Property: not required, but possible to set by models that respond thinking tokens.

At the Moment the only class that extends this class is DeepSeekAssistantMessage

I'd be more than happy to suggest the changes in a pull request.

renemrhfr avatar Aug 25 '25 19:08 renemrhfr

My suggestion is to introduce a new field in AssistantMessage and handle it the same as the toolCalls Property: not required, but possible to set by models that respond thinking tokens.

At the Moment the only class that extends this class is DeepSeekAssistantMessage

I'd be more than happy to suggest the changes in a pull request.

Since @markpollack mentioned that he's already exploring ways to support thinking as a whole(https://github.com/spring-projects/spring-ai/pull/3386#issuecomment-3130804866), I'd prefer to wait for his adjustments. Of course, you're always welcome to submit a PR!

sunyuhan1998 avatar Aug 26 '25 01:08 sunyuhan1998

Hi, was this feature already implemented or are still workarounds being used?

EvalVis avatar Feb 21 '26 19:02 EvalVis