model switch also switches provider (gpt models were sent to the Claude API)
This commit is contained in:
1 parent
658ada46f7
commit
ad73e8f1c2
7 files changed
+171
-21
No files matched your search
+28
-10
@@ -47,13 +47,22 @@ fn reply(id: &Value, r: Result<Value, String>) {
|
||||
/// `state`, `messages`, `fork {id}`, `clear`, `set_model {model}`, `compact`,
|
||||
/// `complete {line, cursor?}` (cursor = byte offset, default end), `sessions {scope?: project|all}`,
|
||||
/// `new`, `resume {path}`. One prompt at a time.
|
||||
pub async fn serve(
|
||||
mut agent: Agent,
|
||||
abort: AbortHandle,
|
||||
specs: Vec<hx_core::command::CmdSpec>,
|
||||
files: Vec<String>,
|
||||
session_dir: std::path::PathBuf,
|
||||
) -> Result<()> {
|
||||
pub struct Ctx {
|
||||
pub specs: Vec<hx_core::command::CmdSpec>,
|
||||
pub files: Vec<String>,
|
||||
pub session_dir: std::path::PathBuf,
|
||||
pub models: Vec<hx_ai::models::ModelInfo>,
|
||||
pub make_provider: fn(hx_ai::auth::Kind) -> hx_ai::Result<Arc<dyn hx_ai::Provider>>,
|
||||
}
|
||||
|
||||
pub async fn serve(mut agent: Agent, abort: AbortHandle, cx: Ctx) -> Result<()> {
|
||||
let Ctx {
|
||||
specs,
|
||||
files,
|
||||
session_dir,
|
||||
models,
|
||||
make_provider,
|
||||
} = cx;
|
||||
agent.bus.add(Notify);
|
||||
let agent = Arc::new(Mutex::new(agent));
|
||||
let busy = Arc::new(std::sync::atomic::AtomicBool::new(false));
|
||||
@@ -136,10 +145,19 @@ pub async fn serve(
|
||||
.map(|_| json!({}))
|
||||
.map_err(|e| e.to_string()),
|
||||
"set_model" => match p["model"].as_str() {
|
||||
Some(m) => {
|
||||
a.model = m.into();
|
||||
Ok(json!({"model": m}))
|
||||
// switch provider too when the model belongs to another one
|
||||
Some(m) => match hx_ai::models::kind_of(&models, m) {
|
||||
Some(k) => make_provider(k).map(|prov| {
|
||||
a.provider = prov;
|
||||
a.model = m.into();
|
||||
json!({"model": m, "provider": format!("{k:?}").to_lowercase()})
|
||||
}),
|
||||
None => {
|
||||
a.model = m.into();
|
||||
Ok(json!({"model": m}))
|
||||
}
|
||||
}
|
||||
.map_err(|e| e.to_string()),
|
||||
None => Err("params.model required".into()),
|
||||
},
|
||||
"compact" => a
|
||||
|
||||
Reference in new issue
Block a user