Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ public record ChatCompletionRequest(// @formatter:off
@JsonProperty("verbosity") String verbosity,
@JsonProperty("prompt_cache_key") String promptCacheKey,
@JsonProperty("safety_identifier") String safetyIdentifier,
Map<String, Object> extraBody) {
@JsonProperty("extra_body") Map<String, Object> extraBody) {

/**
* Compact constructor that ensures extraBody is initialized as a mutable HashMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.openai.OpenAiChatOptions;
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionRequest;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -208,4 +210,25 @@ void testDeserializationWithComplexExtraFields() throws Exception {
assertThat(request.extraBody().get("stop_token_ids")).isInstanceOf(List.class);
}

@Test
void testMergeWithExtraBody() throws Exception {
// Arrange: Create OpenAiChatOptions with extraBody
OpenAiChatOptions requestOptions = OpenAiChatOptions.builder()
.model("test-model")
.extraBody(Map.of("enable_thinking", true, "max_depth", 10))
.build();

// Create empty ChatCompletionRequest
ChatCompletionRequest request = new ChatCompletionRequest(null, null);

// Act: Merge options into request
request = ModelOptionsUtils.merge(requestOptions, request, ChatCompletionRequest.class);

// Assert: Verify extraBody was successfully merged
assertThat(request.extraBody()).isNotNull();
assertThat(request.extraBody()).containsEntry("enable_thinking", true);
assertThat(request.extraBody()).containsEntry("max_depth", 10);
assertThat(request.model()).isEqualTo("test-model");
}

}