Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions crates/axe-core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ pub trait Axe: Send + Sync + 'static {
fn runtime_remove(&self, _runtime: &str) -> Result<String> {
anyhow::bail!("runtime changes need an axe server")
}
/// Makes `model` node runtime `runtime`'s default model on provider
/// `provider` (`runtime::Registry::set_model`): the owner's pick after a
/// key login.
fn runtime_model(&self, _runtime: &str, _provider: &str, _model: &str) -> Result<()> {
anyhow::bail!("runtime changes need an axe server")
}
/// Checks node runtime `runtime`'s login now
/// (`runtime::Registry::check_now`); the outcome comes back as a card.
fn runtime_check(&self, _runtime: &str) -> Result<()> {
Expand Down
48 changes: 27 additions & 21 deletions crates/axe-core/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,24 +177,27 @@ pub enum ConfigFile {
}

/// A provider login a runtime holds, for its config file
/// ([`ConfigFile::render`]): the provider, the runtime's model on it
/// ([`crate::runtime::Runtime::model_of`]) and, for `Other…`, its base URL.
/// ([`ConfigFile::render`]): the provider, the models to declare on it
/// (its row's default first, then a run's rule model;
/// [`crate::runtime::Runtime::held`]) and, for `Other…`, its base URL.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Held {
pub id: &'static str,
pub model: String,
pub models: Vec<String>,
pub base_url: Option<String>,
}

impl Held {
/// A login of row `id` on its default model (tests, and a row the
/// owner picked no model for).
/// A login of row `id` on its default model (tests).
pub fn default_of(id: &'static str) -> Held {
Held {
id,
model: crate::provider::get(id)
.map_or("", |p| p.default_model)
.into(),
models: crate::provider::get(id)
.map(|p| p.default_model)
.filter(|m| !m.is_empty())
.map(String::from)
.into_iter()
.collect(),
base_url: None,
}
}
Expand All @@ -210,7 +213,7 @@ impl ConfigFile {
/// [`ConfigFile::None`]. No secret goes in a file: keys stay in the
/// environment.
pub fn render(&self, held: &[Held]) -> Vec<(&'static str, String)> {
let first = held.iter().find(|h| !h.model.is_empty());
let first = held.iter().find(|h| !h.models.is_empty());
let pretty = |v: &serde_json::Value| serde_json::to_string_pretty(v).expect("json") + "\n";
match self {
ConfigFile::None => vec![],
Expand All @@ -227,12 +230,14 @@ impl ConfigFile {
"update": "disable",
});
if let Some(h) = first {
v["model"] = format!("{}/{}", h.id, h.model).into();
v["model"] = format!("{}/{}", h.id, h.models[0]).into();
}
let mut providers = serde_json::Map::new();
for h in held.iter().filter(|h| !h.model.is_empty()) {
for h in held.iter().filter(|h| !h.models.is_empty()) {
let mut models = serde_json::Map::new();
models.insert(h.model.clone(), serde_json::json!({}));
for m in &h.models {
models.insert(m.clone(), serde_json::json!({}));
}
let mut p = serde_json::json!({"models": models});
if h.custom() {
let Some(url) = &h.base_url else { continue };
Expand Down Expand Up @@ -260,10 +265,10 @@ impl ConfigFile {
});
if let Some(h) = first {
v["defaultProvider"] = h.id.into();
v["defaultModel"] = h.model.clone().into();
v["defaultModel"] = h.models[0].clone().into();
}
let mut providers = serde_json::Map::new();
for h in held.iter().filter(|h| h.custom() && !h.model.is_empty()) {
for h in held.iter().filter(|h| h.custom() && !h.models.is_empty()) {
let (Some(url), Some(row)) = (&h.base_url, crate::provider::get(h.id)) else {
continue;
};
Expand All @@ -274,7 +279,7 @@ impl ConfigFile {
"baseUrl": url,
"api": "openai-completions",
"apiKey": format!("${}", row.env),
"models": [{"id": h.model}],
"models": h.models.iter().map(|m| serde_json::json!({"id": m})).collect::<Vec<_>>(),
}),
);
}
Expand Down Expand Up @@ -816,24 +821,25 @@ mod tests {
"deepseek": {"models": {"deepseek-flash": {}}},
"openrouter": {"models": {"~anthropic/claude-sonnet-latest": {}}}}})
);
// The owner's pick, and `Other…` with its base URL.
// A rule's model declared beside the row's default, and `Other…`
// with its base URL and the model a rule names.
let held = [
Held {
id: "openai",
model: "gpt-6.2-astra".into(),
models: vec!["gpt-6.2-sol".into(), "gpt-6.2-astra".into()],
base_url: None,
},
Held {
id: "other",
model: "qwen2.5-coder:7b".into(),
models: vec!["qwen2.5-coder:7b".into()],
base_url: Some("http://localhost:11434/v1".into()),
},
];
let v: serde_json::Value = serde_json::from_str(&h.config.render(&held)[0].1).unwrap();
assert_eq!(v["model"], "openai/gpt-6.2-astra");
assert_eq!(v["model"], "openai/gpt-6.2-sol");
assert_eq!(
v["provider"]["openai"],
serde_json::json!({"models": {"gpt-6.2-astra": {}}})
serde_json::json!({"models": {"gpt-6.2-sol": {}, "gpt-6.2-astra": {}}})
);
assert_eq!(
v["provider"]["other"],
Expand Down Expand Up @@ -873,7 +879,7 @@ mod tests {
assert_eq!(m["providers"], serde_json::json!({}));
let other = Held {
id: "other",
model: "mock-b".into(),
models: vec!["mock-b".into()],
base_url: Some("https://llm.example.com/v1".into()),
};
let files = h.config.render(&[other]);
Expand Down
Loading
Loading