auto model: per-prompt model/effort routing across providers, @override per turn
This commit is contained in:
1 parent
f1343295d4
commit
b8fc96a3d2
13 files changed
+1201
-17
No files matched your search
@@ -198,6 +198,7 @@ struct App {
|
||||
impl App {
|
||||
/// Mirror a model/provider switch into what the footer shows.
|
||||
fn apply_switch(&mut self, sw: &hx_core::switch::Switched) {
|
||||
self.st.auto = self.sw.is_auto();
|
||||
self.st.kind = sw.kind;
|
||||
self.st.model = sw.model.clone();
|
||||
// keep the level when the new provider has it, else its first (Codex has no "off")
|
||||
@@ -339,6 +340,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
cwd_label: home_short(&cwd),
|
||||
git: git_head(&cwd),
|
||||
st: status::Status {
|
||||
auto: switcher.is_auto(),
|
||||
kind: switcher.kind(),
|
||||
model: agent.model().to_string(),
|
||||
effort: agent.effort(),
|
||||
@@ -527,6 +529,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
app.st.usage.add(u);
|
||||
}
|
||||
if let Event::Stream(hx_ai::StreamEvent::Quota(q)) = &e {
|
||||
app.sw.note_quota(app.st.kind, q);
|
||||
app.st.quota = Some(q.clone());
|
||||
}
|
||||
if let Event::Stream(
|
||||
@@ -545,6 +548,14 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
||||
}
|
||||
Ui::Done(r) => {
|
||||
app.busy = false;
|
||||
{
|
||||
let mut a = agent.lock().await;
|
||||
if let Some(sw) = app.sw.end_turn(&mut a) {
|
||||
app.apply_switch(&sw);
|
||||
app.st.effort = a.effort();
|
||||
app.ctx_max_from(&a);
|
||||
}
|
||||
}
|
||||
app.git = git_head(&cwd);
|
||||
match r {
|
||||
Err(e) if e == "aborted" => app.t.push(Item::Info("aborted".into())),
|
||||
@@ -1422,11 +1433,23 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) {
|
||||
))),
|
||||
Err(e) => app.t.push(Item::Error(e)),
|
||||
},
|
||||
"model" if arg.is_empty() => app.t.push(Item::Info(format!("model: {}", app.st.model))),
|
||||
"model" if arg.is_empty() => app.t.push(Item::Info(format!(
|
||||
"model: {}{}",
|
||||
app.st.model,
|
||||
if app.st.auto { " (auto)" } else { "" }
|
||||
))),
|
||||
"model" if arg == "auto" => {
|
||||
app.sw.set_auto(true);
|
||||
app.st.auto = true;
|
||||
app.t.push(Item::Info(
|
||||
"model: auto. Picked per prompt across logged-in providers; `@opus ...`, `@codex ...`, `@fast ...` force one turn.".into(),
|
||||
));
|
||||
}
|
||||
"model" => {
|
||||
let mut a = agent.lock().await;
|
||||
match app.sw.set_model(&mut a, arg) {
|
||||
Ok(sw) => {
|
||||
app.st.auto = false;
|
||||
app.apply_switch(&sw);
|
||||
app.ctx_max_from(&a);
|
||||
app.t.push(Item::Info(format!(
|
||||
@@ -1508,6 +1531,36 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) {
|
||||
} else {
|
||||
line.clone()
|
||||
}));
|
||||
// auto mode / `@opus ...` override: choose model and thinking for this prompt
|
||||
let routed = {
|
||||
let mut a = agent.lock().await;
|
||||
let is_file = |w: &str| cwd.join(w).is_file();
|
||||
match app.sw.begin_turn(&mut a, &line, &is_file) {
|
||||
Ok(r) => {
|
||||
if let Some(r) = &r {
|
||||
app.apply_switch(&r.sw);
|
||||
app.st.effort = r.pick.effort;
|
||||
app.ctx_max_from(&a);
|
||||
}
|
||||
r
|
||||
}
|
||||
Err(e) => {
|
||||
app.t.push(Item::Error(format!("model choice: {e}")));
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
if let Some(r) = routed {
|
||||
app.t.push(Item::Info(format!(
|
||||
"{} {} ({:?}, think {}): {}",
|
||||
if r.forced { "forced" } else { "auto" },
|
||||
r.pick.model,
|
||||
r.pick.kind,
|
||||
r.pick.effort.name(),
|
||||
r.pick.why
|
||||
)));
|
||||
line = r.prompt;
|
||||
}
|
||||
app.busy = true;
|
||||
app.since = Instant::now();
|
||||
app.run_tokens = (0, 0);
|
||||
@@ -2441,6 +2494,7 @@ mod tests {
|
||||
busy: false,
|
||||
queue: VecDeque::new(),
|
||||
st: status::Status {
|
||||
auto: false,
|
||||
kind: Kind::Claude,
|
||||
model: "m1".into(),
|
||||
effort: hx_ai::Effort::Off,
|
||||
@@ -2563,7 +2617,7 @@ mod tests {
|
||||
for c in "/model ".chars() {
|
||||
key(&mut app, KeyCode::Char(c));
|
||||
}
|
||||
assert_eq!(labels(&app).unwrap().0, ["opus", "sonnet"]);
|
||||
assert_eq!(labels(&app).unwrap().0, ["auto", "opus", "sonnet"]);
|
||||
assert_eq!(key(&mut app, KeyCode::Enter).as_deref(), Some("/model "));
|
||||
|
||||
// @file waits for tab; esc closes; up with popup closed browses history
|
||||
|
||||
@@ -11,6 +11,8 @@ use ratatui::text::{Line, Span};
|
||||
|
||||
/// What the status line and `/usage` report about the running session.
|
||||
pub struct Status {
|
||||
/// `/model auto` is on: the model shown was picked for the last prompt
|
||||
pub auto: bool,
|
||||
pub kind: Kind,
|
||||
pub model: String,
|
||||
pub effort: hx_ai::Effort,
|
||||
@@ -135,8 +137,9 @@ fn left_spans(st: &Status) -> Vec<Span<'static>> {
|
||||
.unwrap_or_default(),
|
||||
};
|
||||
let model = st.model.strip_prefix("claude-").unwrap_or(&st.model);
|
||||
let auto = if st.auto { "auto→" } else { "" };
|
||||
vec![
|
||||
Span::styled(format!("{model} {} ctx ", th.sym.info), th.sec()),
|
||||
Span::styled(format!("{auto}{model} {} ctx ", th.sym.info), th.sec()),
|
||||
Span::styled(th.sym.bar_full.repeat(full), bar_st),
|
||||
Span::styled(th.sym.bar_empty.repeat(10 - full), th.dim()),
|
||||
Span::styled(format!(" {:.0}%{cost}", frac * 100.0), th.sec()),
|
||||
@@ -269,6 +272,7 @@ mod tests {
|
||||
|
||||
fn st() -> Status {
|
||||
Status {
|
||||
auto: false,
|
||||
kind: Kind::Claude,
|
||||
model: "claude-m1".into(),
|
||||
effort: hx_ai::Effort::Off,
|
||||
|
||||
Reference in new issue
Block a user