55import java .time .Duration ;
66import java .util .function .Supplier ;
77
8+ import org .jboss .logging .Logger ;
9+
810import dev .langchain4j .model .anthropic .AnthropicChatModel ;
911import dev .langchain4j .model .anthropic .AnthropicStreamingChatModel ;
1012import dev .langchain4j .model .chat .ChatModel ;
2022
2123@ Recorder
2224public class AnthropicRecorder {
25+ private static final Logger LOG = Logger .getLogger (AnthropicRecorder .class );
26+
2327 private static final String DUMMY_KEY = "dummy" ;
2428
2529 private final RuntimeValue <LangChain4jAnthropicConfig > runtimeConfig ;
@@ -47,14 +51,15 @@ public Supplier<ChatModel> chatModel(String configName) {
4751 .logRequests (firstOrDefault (false , chatModelConfig .logRequests (), anthropicConfig .logRequests ()))
4852 .logResponses (firstOrDefault (false , chatModelConfig .logResponses (), anthropicConfig .logResponses ()))
4953 .timeout (anthropicConfig .timeout ().orElse (Duration .ofSeconds (10 )))
50- .topK (chatModelConfig .topK ())
5154 .maxTokens (chatModelConfig .maxTokens ())
5255 .maxRetries (chatModelConfig .maxRetries ());
5356
5457 if (chatModelConfig .temperature ().isPresent ()) {
5558 builder .temperature (chatModelConfig .temperature ().getAsDouble ());
5659 }
5760
61+ builder .topK (chatModelConfig .topK ().orElse (40 ));
62+
5863 if (chatModelConfig .topP ().isPresent ()) {
5964 builder .topP (chatModelConfig .topP ().getAsDouble ());
6065 }
@@ -65,6 +70,10 @@ public Supplier<ChatModel> chatModel(String configName) {
6570
6671 ChatModelConfig .ThinkingConfig thinkingConfig = chatModelConfig .thinking ();
6772 if (thinkingConfig .type ().isPresent ()) {
73+ if (chatModelConfig .topK ().isPresent ()) {
74+ LOG .warn ("TopK was not configured because thinking was enabled" );
75+ }
76+ builder .topK (null );
6877 builder .thinkingType (thinkingConfig .type ().get ());
6978 }
7079
@@ -115,7 +124,7 @@ public Supplier<StreamingChatModel> streamingChatModel(String configName) {
115124 .logRequests (firstOrDefault (false , chatModelConfig .logRequests (), anthropicConfig .logRequests ()))
116125 .logResponses (firstOrDefault (false , chatModelConfig .logResponses (), anthropicConfig .logResponses ()))
117126 .timeout (anthropicConfig .timeout ().orElse (Duration .ofSeconds (10 )))
118- .topK (chatModelConfig .topK ())
127+ .topK (chatModelConfig .topK (). orElse ( 40 ) )
119128 .maxTokens (chatModelConfig .maxTokens ());
120129
121130 if (chatModelConfig .temperature ().isPresent ()) {
0 commit comments