16
16
17
17
package org .springframework .ai .deepseek .api ;
18
18
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
+
19
26
import com .fasterxml .jackson .annotation .JsonFormat ;
20
27
import com .fasterxml .jackson .annotation .JsonIgnore ;
28
+ import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
21
29
import com .fasterxml .jackson .annotation .JsonInclude ;
22
30
import com .fasterxml .jackson .annotation .JsonInclude .Include ;
23
31
import com .fasterxml .jackson .annotation .JsonProperty ;
32
+ import reactor .core .publisher .Flux ;
33
+ import reactor .core .publisher .Mono ;
34
+
24
35
import org .springframework .ai .model .ApiKey ;
25
36
import org .springframework .ai .model .ChatModelDescription ;
26
37
import org .springframework .ai .model .ModelOptionsUtils ;
35
46
import org .springframework .web .client .ResponseErrorHandler ;
36
47
import org .springframework .web .client .RestClient ;
37
48
import 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 ;
47
49
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 ;
49
53
50
54
/**
51
55
* Single class implementation of the DeepSeek Chat Completion API:
@@ -484,7 +488,7 @@ public void setJsonSchema(String jsonSchema) {
484
488
* @param toolChoice Controls which (if any) function is called by the model. none
485
489
* means the model will not call a function and instead generates a message. auto
486
490
* 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":
488
492
* "my_function"}} forces the model to call that function. none is the default when no
489
493
* functions are present. auto is the default if functions are present. Use the
490
494
* {@link ToolChoiceBuilder} to create the tool choice value.
@@ -587,6 +591,7 @@ public static Object FUNCTION(String functionName) {
587
591
* Applicable only for {@link Role#ASSISTANT} role and null otherwise.
588
592
*/
589
593
@ JsonInclude (Include .NON_NULL )
594
+ @ JsonIgnoreProperties (ignoreUnknown = true )
590
595
public record ChatCompletionMessage (// @formatter:off
591
596
@ JsonProperty ("content" ) Object rawContent ,
592
597
@ JsonProperty ("role" ) Role role ,
@@ -675,6 +680,7 @@ public enum Role {
675
680
* @param function The function definition.
676
681
*/
677
682
@ JsonInclude (Include .NON_NULL )
683
+ @ JsonIgnoreProperties (ignoreUnknown = true )
678
684
public record ToolCall (// @formatter:off
679
685
@ JsonProperty ("index" ) Integer index ,
680
686
@ JsonProperty ("id" ) String id ,
@@ -695,6 +701,7 @@ public ToolCall(String id, String type, ChatCompletionFunction function) {
695
701
* function.
696
702
*/
697
703
@ JsonInclude (Include .NON_NULL )
704
+ @ JsonIgnoreProperties (ignoreUnknown = true )
698
705
public record ChatCompletionFunction (// @formatter:off
699
706
@ JsonProperty ("name" ) String name ,
700
707
@ JsonProperty ("arguments" ) String arguments ) { // @formatter:on
@@ -718,6 +725,7 @@ public record ChatCompletionFunction(// @formatter:off
718
725
* @param usage Usage statistics for the completion request.
719
726
*/
720
727
@ JsonInclude (Include .NON_NULL )
728
+ @ JsonIgnoreProperties (ignoreUnknown = true )
721
729
public record ChatCompletion (// @formatter:off
722
730
@ JsonProperty ("id" ) String id ,
723
731
@ JsonProperty ("choices" ) List <Choice > choices ,
@@ -737,6 +745,7 @@ public record ChatCompletion(// @formatter:off
737
745
* @param logprobs Log probability information for the choice.
738
746
*/
739
747
@ JsonInclude (Include .NON_NULL )
748
+ @ JsonIgnoreProperties (ignoreUnknown = true )
740
749
public record Choice (// @formatter:off
741
750
@ JsonProperty ("finish_reason" ) ChatCompletionFinishReason finishReason ,
742
751
@ JsonProperty ("index" ) Integer index ,
@@ -753,6 +762,7 @@ public record Choice(// @formatter:off
753
762
* @param refusal A list of message refusal tokens with log probability information.
754
763
*/
755
764
@ JsonInclude (Include .NON_NULL )
765
+ @ JsonIgnoreProperties (ignoreUnknown = true )
756
766
public record LogProbs (@ JsonProperty ("content" ) List <Content > content ,
757
767
@ JsonProperty ("refusal" ) List <Content > refusal ) {
758
768
@@ -771,6 +781,7 @@ public record LogProbs(@JsonProperty("content") List<Content> content,
771
781
* requested top_logprobs returned.
772
782
*/
773
783
@ JsonInclude (Include .NON_NULL )
784
+ @ JsonIgnoreProperties (ignoreUnknown = true )
774
785
public record Content (// @formatter:off
775
786
@ JsonProperty ("token" ) String token ,
776
787
@ JsonProperty ("logprob" ) Float logprob ,
@@ -789,6 +800,7 @@ public record Content(// @formatter:off
789
800
* is no bytes representation for the token.
790
801
*/
791
802
@ JsonInclude (Include .NON_NULL )
803
+ @ JsonIgnoreProperties (ignoreUnknown = true )
792
804
public record TopLogProbs (// @formatter:off
793
805
@ JsonProperty ("token" ) String token ,
794
806
@ JsonProperty ("logprob" ) Float logprob ,
@@ -812,6 +824,7 @@ public record TopLogProbs(// @formatter:off
812
824
* @param promptTokensDetails Breakdown of tokens used in the prompt.
813
825
*/
814
826
@ JsonInclude (Include .NON_NULL )
827
+ @ JsonIgnoreProperties (ignoreUnknown = true )
815
828
public record Usage (// @formatter:off
816
829
@ JsonProperty ("completion_tokens" ) Integer completionTokens ,
817
830
@ JsonProperty ("prompt_tokens" ) Integer promptTokens ,
@@ -828,6 +841,7 @@ public Usage(Integer completionTokens, Integer promptTokens, Integer totalTokens
828
841
* @param cachedTokens Cached tokens present in the prompt.
829
842
*/
830
843
@ JsonInclude (Include .NON_NULL )
844
+ @ JsonIgnoreProperties (ignoreUnknown = true )
831
845
public record PromptTokensDetails (// @formatter:off
832
846
@ JsonProperty ("cached_tokens" ) Integer cachedTokens ) { // @formatter:on
833
847
}
@@ -853,6 +867,7 @@ public record PromptTokensDetails(// @formatter:off
853
867
* only if the StreamOptions.includeUsage is set to true.
854
868
*/
855
869
@ JsonInclude (Include .NON_NULL )
870
+ @ JsonIgnoreProperties (ignoreUnknown = true )
856
871
public record ChatCompletionChunk (// @formatter:off
857
872
@ JsonProperty ("id" ) String id ,
858
873
@ JsonProperty ("choices" ) List <ChunkChoice > choices ,
@@ -872,6 +887,7 @@ public record ChatCompletionChunk(// @formatter:off
872
887
* @param logprobs Log probability information for the choice.
873
888
*/
874
889
@ JsonInclude (Include .NON_NULL )
890
+ @ JsonIgnoreProperties (ignoreUnknown = true )
875
891
public record ChunkChoice (// @formatter:off
876
892
@ JsonProperty ("finish_reason" ) ChatCompletionFinishReason finishReason ,
877
893
@ JsonProperty ("index" ) Integer index ,
0 commit comments