Skip to content

Commit 9ec8146

Browse files
committed
Fix truncating responses.
1 parent 7ddbe9b commit 9ec8146

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

crates/rustyclaw-core/src/gateway/providers.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ pub async fn call_openai_with_tools(
957957
let mut body = json!({
958958
"model": req.model,
959959
"messages": messages,
960+
"max_tokens": 16384,
960961
"stream": true,
961962
"stream_options": { "include_usage": true },
962963
});
@@ -1107,8 +1108,8 @@ pub async fn call_anthropic_with_tools(
11071108
// Use streaming when we have a writer to forward chunks to
11081109
let use_streaming = writer.is_some();
11091110

1110-
// Increase max_tokens when streaming to allow for longer responses
1111-
let max_tokens = if use_streaming { 16384 } else { 4096 };
1111+
// Allow generous output length to avoid truncation on long responses
1112+
let max_tokens = 16384;
11121113

11131114
let mut body = json!({
11141115
"model": req.model,

crates/rustyclaw-core/src/streaming.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub async fn call_openai_streaming(
7878
let mut body = json!({
7979
"model": req.model,
8080
"messages": messages,
81+
"max_tokens": 16384,
8182
"stream": true,
8283
});
8384

@@ -226,12 +227,12 @@ pub async fn call_anthropic_streaming(
226227
})
227228
.collect();
228229

229-
// Determine max_tokens based on whether thinking is enabled
230-
// Extended thinking requires higher max_tokens to accommodate thinking + response
230+
// Allow generous output length to avoid truncation on long responses.
231+
// Extended thinking needs even more room, but 16384 is a good baseline.
231232
let max_tokens = if req.thinking_budget.is_some() {
232-
16384 // Allow room for thinking + response
233+
32768
233234
} else {
234-
4096
235+
16384
235236
};
236237

237238
let mut body = json!({

0 commit comments

Comments
 (0)