Skip to content

Commit c34a575

Browse files
shukladivyanshcopybara-github
authored andcommitted
feat: Allow max tokens to be customizable in Claude
PiperOrigin-RevId: 789658952
1 parent af11445 commit c34a575

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

core/src/main/java/com/google/adk/models/Claude.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
public class Claude extends BaseLlm {
6161

6262
private static final Logger logger = LoggerFactory.getLogger(Claude.class);
63-
private static final int MAX_TOKEN = 8192;
63+
private int maxTokens = 8192;
6464
private final AnthropicClient anthropicClient;
6565

6666
/**
@@ -74,6 +74,12 @@ public Claude(String modelName, AnthropicClient anthropicClient) {
7474
this.anthropicClient = anthropicClient;
7575
}
7676

77+
public Claude(String modelName, AnthropicClient anthropicClient, int maxTokens) {
78+
super(modelName);
79+
this.anthropicClient = anthropicClient;
80+
this.maxTokens = maxTokens;
81+
}
82+
7783
@Override
7884
public Flowable<LlmResponse> generateContent(LlmRequest llmRequest, boolean stream) {
7985
// TODO: Switch to streaming API.
@@ -125,7 +131,7 @@ public Flowable<LlmResponse> generateContent(LlmRequest llmRequest, boolean stre
125131
.messages(messages)
126132
.tools(tools)
127133
.toolChoice(toolChoice)
128-
.maxTokens(MAX_TOKEN)
134+
.maxTokens(this.maxTokens)
129135
.build());
130136

131137
logger.debug("Claude response: {}", message);

0 commit comments

Comments
 (0)