feat: make context limit configurable in API settings
Add context limit field to API settings that: - Stores context limit in config (defaults to 200000) - Allows users to set custom limits for different models - Uses configured limit in token counter display - Shows format like "2.5k / 200k tokens" using actual limit This allows proper token tracking for non-Claude models with different context windows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,12 @@ struct ApiConfig {
|
||||
active_character_id: Option<String>,
|
||||
#[serde(default)]
|
||||
stream: bool,
|
||||
#[serde(default = "default_context_limit")]
|
||||
context_limit: u32,
|
||||
}
|
||||
|
||||
fn default_context_limit() -> u32 {
|
||||
200000
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -1161,7 +1167,7 @@ async fn validate_api(base_url: String, api_key: String) -> Result<Vec<String>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn save_api_config(base_url: String, api_key: String, model: String, stream: bool) -> Result<(), String> {
|
||||
async fn save_api_config(base_url: String, api_key: String, model: String, stream: bool, context_limit: u32) -> Result<(), String> {
|
||||
// Preserve existing active_character_id if it exists
|
||||
let active_character_id = load_config().and_then(|c| c.active_character_id);
|
||||
|
||||
@@ -1171,6 +1177,7 @@ async fn save_api_config(base_url: String, api_key: String, model: String, strea
|
||||
model,
|
||||
active_character_id,
|
||||
stream,
|
||||
context_limit,
|
||||
};
|
||||
save_config(&config)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user