Skip to content

Conversation

@SenreySong
Copy link

  • OpenAiChatOptions.extraBody: Support for custom parameter extension
  • ChatCompletionMessage.reasoningContent: Support for reasoning content field

@SenreySong SenreySong changed the title Add support for extraBody and reasoningContent OpenAiApi Add support for extraBody and reasoningContent Sep 4, 2025
SenreySong and others added 2 commits September 4, 2025 17:18
- OpenAiChatOptions.extraBody: Support for custom parameter extension
- ChatCompletionMessage.reasoningContent: Support for reasoning content field

Signed-off-by: SenreySong <[email protected]>
Signed-off-by: SenreySong <[email protected]>
@SenreySong SenreySong force-pushed the main branch 2 times, most recently from ee5e0f1 to bbcb968 Compare September 8, 2025 03:57
@ilayaperumalg
Copy link
Member

@SenreySong Thanks for the changes. Could you fix(/remove) the formatting changes as part of the PR? This makes it challenging to review the actual changes?

@ilayaperumalg ilayaperumalg self-assigned this Sep 9, 2025
@SenreySong
Copy link
Author

@SenreySong Thanks for the changes. Could you fix(/remove) the formatting changes as part of the PR? This makes it challenging to review the actual changes?

No problem. I'll fix the formatting issues.

Signed-off-by: SenreySong <[email protected]>

refactor(spring-ai-openai): fix import style

Signed-off-by: SenreySong <[email protected]>

refactor(spring-ai-openai): fix code style

Signed-off-by: SenreySong <[email protected]>

refactor(spring-ai-openai): fix code style

Signed-off-by: SenreySong <[email protected]>
@ilayaperumalg ilayaperumalg added this to the 1.1.0.M3 milestone Sep 24, 2025
@ilayaperumalg ilayaperumalg modified the milestones: 1.1.0.M3, 1.1.0.M4 Oct 9, 2025
@markpollack markpollack self-assigned this Oct 20, 2025
markpollack added a commit that referenced this pull request Nov 7, 2025
Squashed 17 commits from PR #4309

Signed-off-by: Alexandros Pappas <[email protected]>
Signed-off-by: Daniel Garnier-Moiroux <[email protected]>
Signed-off-by: Ilayaperumal Gopinathan <[email protected]>
Signed-off-by: Mark Pollack <[email protected]>
Signed-off-by: SenreySong <[email protected]>
Signed-off-by: Senrey_Song <[email protected]>
Signed-off-by: Łukasz Jernaś <[email protected]>

Refactor extraBody to use @JsonAnyGetter for flat JSON serialization

Replace manual JSON merging with Jackson @JsonAnyGetter annotation to flatten
extraBody parameters to top-level JSON, matching OpenAI SDK behavior for
compatibility with vLLM, Ollama, and other OpenAI-compatible servers.

- Add @JsonAnyGetter to extraBody() accessor method
- Remove ObjectMapper instance field and createDynamicRequestBody() method
- Simplify WebClient calls to use .bodyValue(chatRequest) directly
- Add ExtraBodySerializationTest to verify correct flat serialization
- Fix unrelated OpenAiSpeechModelIT compilation error
@ilayaperumalg
Copy link
Member

@SenreySong Thank you for the PR! This has been merged via ec717c1

return requestNode;
}

// 添加额外字段

Choose a reason for hiding this comment

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

hah

Copy link
Author

Choose a reason for hiding this comment

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

OMG!

@Wendell99
Copy link

@ilayaperumalg @SenreySong It seems that the extraBody parameter isn't working in Spring AI 1.1.0.
Am I using it incorrectly? Here's my code:
OpenAiChatOptions openAiChatOptions = OpenAiChatOptions.builder().model("qwen3-8b").extraBody(Map.of("enable_thinking", false)).build();
OpenAiChatModel openAiChatModel = OpenAiChatModel.builder().openAiApi(openAiApi)
.defaultOptions(openAiChatOptions)
.build();
openAiChatModel.stream(new Prompt("Hello", openAiChatOptions))...subscribe();

@SenreySong
Copy link
Author

@Wendell99 Your usage is correct — the issue was that extraBody lacked @JsonProperty, so it got filtered out during merge. Fix submitted.

@Wendell99
Copy link

@SenreySong Your commit has @JsonProperty on extraBody, but it’s not present in v1.1.0 — weird!

@SenreySong
Copy link
Author

@SenreySong Your commit has @JsonProperty on extraBody, but it’s not present in v1.1.0 — weird!

Actually, my commit initially added @JsonProperty, but later reverted to using @JsonAnySetter/@JsonAnyGetter for better flexibility. This change triggered the bug since the merge operation doesn't recognize extraBody as a field to preserve. I've now submitted a fix to explicitly handle extraBody during merging to prevent this issue.

ralla0405 pushed a commit to ralla0405/spring-ai that referenced this pull request Nov 28, 2025
Squashed 17 commits from PR spring-projects#4309

Signed-off-by: Alexandros Pappas <[email protected]>
Signed-off-by: Daniel Garnier-Moiroux <[email protected]>
Signed-off-by: Ilayaperumal Gopinathan <[email protected]>
Signed-off-by: Mark Pollack <[email protected]>
Signed-off-by: SenreySong <[email protected]>
Signed-off-by: Senrey_Song <[email protected]>
Signed-off-by: Łukasz Jernaś <[email protected]>

Refactor extraBody to use @JsonAnyGetter for flat JSON serialization

Replace manual JSON merging with Jackson @JsonAnyGetter annotation to flatten
extraBody parameters to top-level JSON, matching OpenAI SDK behavior for
compatibility with vLLM, Ollama, and other OpenAI-compatible servers.

- Add @JsonAnyGetter to extraBody() accessor method
- Remove ObjectMapper instance field and createDynamicRequestBody() method
- Simplify WebClient calls to use .bodyValue(chatRequest) directly
- Add ExtraBodySerializationTest to verify correct flat serialization
- Fix unrelated OpenAiSpeechModelIT compilation error

Signed-off-by: logan-mac <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants