1616
1717package org .springframework .ai .deepseek .api ;
1818
19+ import java .util .List ;
20+ import java .util .Map ;
21+ import java .util .Objects ;
22+ import java .util .concurrent .atomic .AtomicBoolean ;
23+ import java .util .function .Consumer ;
24+ import java .util .function .Predicate ;
25+
1926import com .fasterxml .jackson .annotation .JsonFormat ;
2027import com .fasterxml .jackson .annotation .JsonIgnore ;
28+ import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
2129import com .fasterxml .jackson .annotation .JsonInclude ;
2230import com .fasterxml .jackson .annotation .JsonInclude .Include ;
2331import com .fasterxml .jackson .annotation .JsonProperty ;
32+ import reactor .core .publisher .Flux ;
33+ import reactor .core .publisher .Mono ;
34+
2435import org .springframework .ai .model .ApiKey ;
2536import org .springframework .ai .model .ChatModelDescription ;
2637import org .springframework .ai .model .ModelOptionsUtils ;
3546import org .springframework .web .client .ResponseErrorHandler ;
3647import org .springframework .web .client .RestClient ;
3748import org .springframework .web .reactive .function .client .WebClient ;
38- import reactor .core .publisher .Flux ;
39- import reactor .core .publisher .Mono ;
40-
41- import java .util .List ;
42- import java .util .Map ;
43- import java .util .Objects ;
44- import java .util .concurrent .atomic .AtomicBoolean ;
45- import java .util .function .Consumer ;
46- import java .util .function .Predicate ;
4749
48- import static org .springframework .ai .deepseek .api .common .DeepSeekConstants .*;
50+ import static org .springframework .ai .deepseek .api .common .DeepSeekConstants .DEFAULT_BASE_URL ;
51+ import static org .springframework .ai .deepseek .api .common .DeepSeekConstants .DEFAULT_BETA_PATH ;
52+ import static org .springframework .ai .deepseek .api .common .DeepSeekConstants .DEFAULT_COMPLETIONS_PATH ;
4953
5054/**
5155 * Single class implementation of the DeepSeek Chat Completion API:
@@ -484,7 +488,7 @@ public void setJsonSchema(String jsonSchema) {
484488 * @param toolChoice Controls which (if any) function is called by the model. none
485489 * means the model will not call a function and instead generates a message. auto
486490 * means the model can pick between generating a message or calling a function.
487- * Specifying a particular function via {"type: "function", "function": {"name":
491+ * Specifying a particular function via {"type" : "function", "function": {"name":
488492 * "my_function"}} forces the model to call that function. none is the default when no
489493 * functions are present. auto is the default if functions are present. Use the
490494 * {@link ToolChoiceBuilder} to create the tool choice value.
@@ -587,6 +591,7 @@ public static Object FUNCTION(String functionName) {
587591 * Applicable only for {@link Role#ASSISTANT} role and null otherwise.
588592 */
589593 @ JsonInclude (Include .NON_NULL )
594+ @ JsonIgnoreProperties (ignoreUnknown = true )
590595 public record ChatCompletionMessage (// @formatter:off
591596 @ JsonProperty ("content" ) Object rawContent ,
592597 @ JsonProperty ("role" ) Role role ,
@@ -675,6 +680,7 @@ public enum Role {
675680 * @param function The function definition.
676681 */
677682 @ JsonInclude (Include .NON_NULL )
683+ @ JsonIgnoreProperties (ignoreUnknown = true )
678684 public record ToolCall (// @formatter:off
679685 @ JsonProperty ("index" ) Integer index ,
680686 @ JsonProperty ("id" ) String id ,
@@ -695,6 +701,7 @@ public ToolCall(String id, String type, ChatCompletionFunction function) {
695701 * function.
696702 */
697703 @ JsonInclude (Include .NON_NULL )
704+ @ JsonIgnoreProperties (ignoreUnknown = true )
698705 public record ChatCompletionFunction (// @formatter:off
699706 @ JsonProperty ("name" ) String name ,
700707 @ JsonProperty ("arguments" ) String arguments ) { // @formatter:on
@@ -718,6 +725,7 @@ public record ChatCompletionFunction(// @formatter:off
718725 * @param usage Usage statistics for the completion request.
719726 */
720727 @ JsonInclude (Include .NON_NULL )
728+ @ JsonIgnoreProperties (ignoreUnknown = true )
721729 public record ChatCompletion (// @formatter:off
722730 @ JsonProperty ("id" ) String id ,
723731 @ JsonProperty ("choices" ) List <Choice > choices ,
@@ -737,6 +745,7 @@ public record ChatCompletion(// @formatter:off
737745 * @param logprobs Log probability information for the choice.
738746 */
739747 @ JsonInclude (Include .NON_NULL )
748+ @ JsonIgnoreProperties (ignoreUnknown = true )
740749 public record Choice (// @formatter:off
741750 @ JsonProperty ("finish_reason" ) ChatCompletionFinishReason finishReason ,
742751 @ JsonProperty ("index" ) Integer index ,
@@ -753,6 +762,7 @@ public record Choice(// @formatter:off
753762 * @param refusal A list of message refusal tokens with log probability information.
754763 */
755764 @ JsonInclude (Include .NON_NULL )
765+ @ JsonIgnoreProperties (ignoreUnknown = true )
756766 public record LogProbs (@ JsonProperty ("content" ) List <Content > content ,
757767 @ JsonProperty ("refusal" ) List <Content > refusal ) {
758768
@@ -771,6 +781,7 @@ public record LogProbs(@JsonProperty("content") List<Content> content,
771781 * requested top_logprobs returned.
772782 */
773783 @ JsonInclude (Include .NON_NULL )
784+ @ JsonIgnoreProperties (ignoreUnknown = true )
774785 public record Content (// @formatter:off
775786 @ JsonProperty ("token" ) String token ,
776787 @ JsonProperty ("logprob" ) Float logprob ,
@@ -789,6 +800,7 @@ public record Content(// @formatter:off
789800 * is no bytes representation for the token.
790801 */
791802 @ JsonInclude (Include .NON_NULL )
803+ @ JsonIgnoreProperties (ignoreUnknown = true )
792804 public record TopLogProbs (// @formatter:off
793805 @ JsonProperty ("token" ) String token ,
794806 @ JsonProperty ("logprob" ) Float logprob ,
@@ -812,6 +824,7 @@ public record TopLogProbs(// @formatter:off
812824 * @param promptTokensDetails Breakdown of tokens used in the prompt.
813825 */
814826 @ JsonInclude (Include .NON_NULL )
827+ @ JsonIgnoreProperties (ignoreUnknown = true )
815828 public record Usage (// @formatter:off
816829 @ JsonProperty ("completion_tokens" ) Integer completionTokens ,
817830 @ JsonProperty ("prompt_tokens" ) Integer promptTokens ,
@@ -828,6 +841,7 @@ public Usage(Integer completionTokens, Integer promptTokens, Integer totalTokens
828841 * @param cachedTokens Cached tokens present in the prompt.
829842 */
830843 @ JsonInclude (Include .NON_NULL )
844+ @ JsonIgnoreProperties (ignoreUnknown = true )
831845 public record PromptTokensDetails (// @formatter:off
832846 @ JsonProperty ("cached_tokens" ) Integer cachedTokens ) { // @formatter:on
833847 }
@@ -853,6 +867,7 @@ public record PromptTokensDetails(// @formatter:off
853867 * only if the StreamOptions.includeUsage is set to true.
854868 */
855869 @ JsonInclude (Include .NON_NULL )
870+ @ JsonIgnoreProperties (ignoreUnknown = true )
856871 public record ChatCompletionChunk (// @formatter:off
857872 @ JsonProperty ("id" ) String id ,
858873 @ JsonProperty ("choices" ) List <ChunkChoice > choices ,
@@ -872,6 +887,7 @@ public record ChatCompletionChunk(// @formatter:off
872887 * @param logprobs Log probability information for the choice.
873888 */
874889 @ JsonInclude (Include .NON_NULL )
890+ @ JsonIgnoreProperties (ignoreUnknown = true )
875891 public record ChunkChoice (// @formatter:off
876892 @ JsonProperty ("finish_reason" ) ChatCompletionFinishReason finishReason ,
877893 @ JsonProperty ("index" ) Integer index ,
0 commit comments