feat: add editing and MCP command handling, enhance SSE streaming with usage tracking
- Implemented `Edit` and `McpAdd` commands in the command parser and handler. - Added a new `stream` module to the runtime for handling streaming events. - Enhanced `SseParser` to parse usage information from SSE events. - Introduced `ToolCallAccumulator` for tracking tool calls independently. - Updated `AppStateRest` to include `app_config` and `MiscState` to track `effort_level` and `selected_index`. - Modified `LlmClient` to support streaming responses with usage tracking. - Improved error handling and retry logic in the streaming API calls. - Added tests for new features and improved markdown rendering in the chat view.
This commit is contained in:
@@ -2,6 +2,21 @@ use crate::app::state::rest::AppStateRest;
|
||||
|
||||
pub const EFFORT_LEVELS: &[&str] = &["low", "medium", "high", "xhigh", "max"];
|
||||
|
||||
/// Multiplier applied to the user's configured `max_tokens`, and the temperature to use,
|
||||
/// for each entry in `EFFORT_LEVELS` (same index). Higher effort trades a larger token
|
||||
/// budget for lower temperature (more deterministic, more room to reason/act).
|
||||
const MAX_TOKENS_MULTIPLIER: &[f32] = &[0.5, 1.0, 1.5, 2.0, 3.0];
|
||||
const TEMPERATURE_OVERRIDE: &[f32] = &[0.9, 0.7, 0.5, 0.3, 0.1];
|
||||
|
||||
/// Maps an effort level index to the `(temperature, max_tokens)` pair that should be sent
|
||||
/// to the LLM, scaling the user's configured `max_tokens` by the level's multiplier.
|
||||
pub fn generation_params(level: usize, base_max_tokens: u32) -> (f32, u32) {
|
||||
let idx = level.min(EFFORT_LEVELS.len() - 1);
|
||||
let temperature = TEMPERATURE_OVERRIDE[idx];
|
||||
let max_tokens = ((base_max_tokens as f32) * MAX_TOKENS_MULTIPLIER[idx]) as u32;
|
||||
(temperature, max_tokens.max(256))
|
||||
}
|
||||
|
||||
pub fn current_effort(state: &AppStateRest) -> usize {
|
||||
state.misc.effort_level.min(EFFORT_LEVELS.len() - 1)
|
||||
}
|
||||
@@ -14,5 +29,10 @@ pub fn current_effort_str(state: &AppStateRest) -> &'static str {
|
||||
pub fn cycle_effort(state: &mut AppStateRest) {
|
||||
let current = current_effort(state);
|
||||
state.misc.effort_level = (current + 1) % EFFORT_LEVELS.len();
|
||||
let label = current_effort_str(state);
|
||||
state.push_toast(crate::app::state::types::Toast::new(
|
||||
crate::app::state::types::ToastKind::Info,
|
||||
format!("Effort: {}", label),
|
||||
));
|
||||
state.dirty = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user