Apps token limit (#7474)
Co-authored-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -290,8 +290,7 @@ impl AppsManagerClient {
|
|||||||
let messages = vec![Message::user().with_text(&user_prompt)];
|
let messages = vec![Message::user().with_text(&user_prompt)];
|
||||||
let tools = vec![Self::create_app_content_tool()];
|
let tools = vec![Self::create_app_content_tool()];
|
||||||
|
|
||||||
let mut model_config = provider.get_model_config();
|
let model_config = provider.get_model_config();
|
||||||
model_config.max_tokens = Some(16384);
|
|
||||||
|
|
||||||
let (response, usage) = provider
|
let (response, usage) = provider
|
||||||
.complete(&model_config, session_id, &system_prompt, &messages, &tools)
|
.complete(&model_config, session_id, &system_prompt, &messages, &tools)
|
||||||
@@ -330,8 +329,7 @@ impl AppsManagerClient {
|
|||||||
let messages = vec![Message::user().with_text(&user_prompt)];
|
let messages = vec![Message::user().with_text(&user_prompt)];
|
||||||
let tools = vec![Self::update_app_content_tool()];
|
let tools = vec![Self::update_app_content_tool()];
|
||||||
|
|
||||||
let mut model_config = provider.get_model_config();
|
let model_config = provider.get_model_config();
|
||||||
model_config.max_tokens = Some(16384);
|
|
||||||
|
|
||||||
let (response, usage) = provider
|
let (response, usage) = provider
|
||||||
.complete(&model_config, session_id, &system_prompt, &messages, &tools)
|
.complete(&model_config, session_id, &system_prompt, &messages, &tools)
|
||||||
|
|||||||
@@ -280,7 +280,6 @@ impl ModelConfig {
|
|||||||
return tokens;
|
return tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 2: Global default
|
|
||||||
4_096
|
4_096
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -431,10 +431,13 @@ pub fn create_request(
|
|||||||
|
|
||||||
let is_thinking_enabled = std::env::var("CLAUDE_THINKING_ENABLED").is_ok();
|
let is_thinking_enabled = std::env::var("CLAUDE_THINKING_ENABLED").is_ok();
|
||||||
if is_thinking_enabled {
|
if is_thinking_enabled {
|
||||||
let budget_tokens = std::env::var("CLAUDE_THINKING_BUDGET")
|
// Anthropic requires budget_tokens >= 1024
|
||||||
.unwrap_or_else(|_| "16000".to_string())
|
const DEFAULT_THINKING_BUDGET: i32 = 16000;
|
||||||
.parse()
|
let raw_budget_tokens: i32 = std::env::var("CLAUDE_THINKING_BUDGET")
|
||||||
.unwrap_or(16000);
|
.ok()
|
||||||
|
.and_then(|s| s.parse().ok())
|
||||||
|
.unwrap_or(DEFAULT_THINKING_BUDGET);
|
||||||
|
let budget_tokens: i32 = std::cmp::max(1024, raw_budget_tokens);
|
||||||
|
|
||||||
payload
|
payload
|
||||||
.as_object_mut()
|
.as_object_mut()
|
||||||
|
|||||||
@@ -613,19 +613,19 @@ pub fn create_request(
|
|||||||
|
|
||||||
let is_thinking_enabled = std::env::var("CLAUDE_THINKING_ENABLED").is_ok();
|
let is_thinking_enabled = std::env::var("CLAUDE_THINKING_ENABLED").is_ok();
|
||||||
if is_claude_sonnet && is_thinking_enabled {
|
if is_claude_sonnet && is_thinking_enabled {
|
||||||
// Minimum budget_tokens is 1024
|
// Anthropic requires budget_tokens >= 1024
|
||||||
let budget_tokens = std::env::var("CLAUDE_THINKING_BUDGET")
|
const DEFAULT_THINKING_BUDGET: i32 = 16000;
|
||||||
.unwrap_or_else(|_| "16000".to_string())
|
let budget_tokens: i32 = std::env::var("CLAUDE_THINKING_BUDGET")
|
||||||
.parse()
|
.ok()
|
||||||
.unwrap_or(16000);
|
.and_then(|s| s.parse().ok())
|
||||||
|
.unwrap_or(DEFAULT_THINKING_BUDGET);
|
||||||
|
|
||||||
// For Claude models with thinking enabled, we need to add max_tokens + budget_tokens
|
// With thinking enabled, max_tokens must include both output and thinking budget
|
||||||
// Default to 8192 (Claude max output) + budget if not specified
|
let max_tokens = model_config.max_output_tokens() + budget_tokens;
|
||||||
let max_completion_tokens = model_config.max_tokens.unwrap_or(8192);
|
payload
|
||||||
payload.as_object_mut().unwrap().insert(
|
.as_object_mut()
|
||||||
"max_tokens".to_string(),
|
.unwrap()
|
||||||
json!(max_completion_tokens + budget_tokens),
|
.insert("max_tokens".to_string(), json!(max_tokens));
|
||||||
);
|
|
||||||
|
|
||||||
payload.as_object_mut().unwrap().insert(
|
payload.as_object_mut().unwrap().insert(
|
||||||
"thinking".to_string(),
|
"thinking".to_string(),
|
||||||
@@ -650,18 +650,16 @@ pub fn create_request(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// open ai reasoning models use max_completion_tokens instead of max_tokens
|
// OpenAI reasoning models use max_completion_tokens instead of max_tokens
|
||||||
if let Some(tokens) = model_config.max_tokens {
|
let key = if is_openai_reasoning_model {
|
||||||
let key = if is_openai_reasoning_model {
|
"max_completion_tokens"
|
||||||
"max_completion_tokens"
|
} else {
|
||||||
} else {
|
"max_tokens"
|
||||||
"max_tokens"
|
};
|
||||||
};
|
payload
|
||||||
payload
|
.as_object_mut()
|
||||||
.as_object_mut()
|
.unwrap()
|
||||||
.unwrap()
|
.insert(key.to_string(), json!(model_config.max_output_tokens()));
|
||||||
.insert(key.to_string(), json!(tokens));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply cache control for Claude models to enable prompt caching
|
// Apply cache control for Claude models to enable prompt caching
|
||||||
|
|||||||
@@ -592,18 +592,11 @@ pub fn create_request(
|
|||||||
|
|
||||||
let thinking_config = get_thinking_config(model_config);
|
let thinking_config = get_thinking_config(model_config);
|
||||||
|
|
||||||
let generation_config = if model_config.temperature.is_some()
|
let generation_config = Some(GenerationConfig {
|
||||||
|| model_config.max_tokens.is_some()
|
temperature: model_config.temperature.map(|t| t as f64),
|
||||||
|| thinking_config.is_some()
|
max_output_tokens: Some(model_config.max_output_tokens()),
|
||||||
{
|
thinking_config,
|
||||||
Some(GenerationConfig {
|
});
|
||||||
temperature: model_config.temperature.map(|t| t as f64),
|
|
||||||
max_output_tokens: model_config.max_tokens,
|
|
||||||
thinking_config,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let request = GoogleRequest {
|
let request = GoogleRequest {
|
||||||
system_instruction: SystemInstruction {
|
system_instruction: SystemInstruction {
|
||||||
|
|||||||
@@ -828,18 +828,16 @@ pub fn create_request(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// o1 models use max_completion_tokens instead of max_tokens
|
// o1/o3 models use max_completion_tokens instead of max_tokens
|
||||||
if let Some(tokens) = model_config.max_tokens {
|
let key = if is_ox_model {
|
||||||
let key = if is_ox_model {
|
"max_completion_tokens"
|
||||||
"max_completion_tokens"
|
} else {
|
||||||
} else {
|
"max_tokens"
|
||||||
"max_tokens"
|
};
|
||||||
};
|
payload
|
||||||
payload
|
.as_object_mut()
|
||||||
.as_object_mut()
|
.unwrap()
|
||||||
.unwrap()
|
.insert(key.to_string(), json!(model_config.max_output_tokens()));
|
||||||
.insert(key.to_string(), json!(tokens));
|
|
||||||
}
|
|
||||||
|
|
||||||
if for_streaming {
|
if for_streaming {
|
||||||
payload["stream"] = json!(true);
|
payload["stream"] = json!(true);
|
||||||
|
|||||||
@@ -460,12 +460,10 @@ pub fn create_responses_request(
|
|||||||
.insert("temperature".to_string(), json!(temp));
|
.insert("temperature".to_string(), json!(temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(tokens) = model_config.max_tokens {
|
payload.as_object_mut().unwrap().insert(
|
||||||
payload
|
"max_output_tokens".to_string(),
|
||||||
.as_object_mut()
|
json!(model_config.max_output_tokens()),
|
||||||
.unwrap()
|
);
|
||||||
.insert("max_output_tokens".to_string(), json!(tokens));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(payload)
|
Ok(payload)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -353,11 +353,10 @@ pub fn create_request(
|
|||||||
format_tools(tools)
|
format_tools(tools)
|
||||||
};
|
};
|
||||||
|
|
||||||
let max_tokens = model_config.max_tokens.unwrap_or(4096);
|
|
||||||
let mut payload = json!({
|
let mut payload = json!({
|
||||||
"model": model_config.model_name,
|
"model": model_config.model_name,
|
||||||
"messages": snowflake_messages,
|
"messages": snowflake_messages,
|
||||||
"max_tokens": max_tokens,
|
"max_tokens": model_config.max_output_tokens(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add tools if present and not a description request
|
// Add tools if present and not a description request
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ impl SageMakerTgiProvider {
|
|||||||
let request = json!({
|
let request = json!({
|
||||||
"inputs": prompt,
|
"inputs": prompt,
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"max_new_tokens": self.model.max_tokens.unwrap_or(150),
|
"max_new_tokens": self.model.max_output_tokens(),
|
||||||
"temperature": self.model.temperature.unwrap_or(0.7),
|
"temperature": self.model.temperature.unwrap_or(0.7),
|
||||||
"do_sample": true,
|
"do_sample": true,
|
||||||
"return_full_text": false
|
"return_full_text": false
|
||||||
|
|||||||
Reference in New Issue
Block a user