Route auxiliary requests through configured models

This commit is contained in:
HoshizukiMio
2026-11-17 18:58:07 +08:00
parent 6e538749a6
commit 4b053c2af9
3 changed files with 41 additions and 14 deletions

View File

@@ -4558,6 +4558,7 @@ pub(crate) fn resolve_aux_model_sampling_config(
alpha_test_key: Option<String>,
client_version: Option<String>,
) -> Option<SamplerConfig> {
let account_login = Distribution::current().allows(Capability::AccountLogin);
let catalog_entry = find_model_by_id(models, model_id).cloned();
if let Some(entry) = &catalog_entry {
let credentials = resolve_credentials_enforced(entry, session_key, disable_api_key_auth);
@@ -4569,7 +4570,9 @@ pub(crate) fn resolve_aux_model_sampling_config(
None,
None,
);
if sampler.api_key.is_some() {
if sampler.api_key.is_some()
|| (!account_login && entry.effective_auth_provider().is_none())
{
return Some(sampler);
}
if entry.effective_auth_provider().is_some() {
@@ -4580,6 +4583,9 @@ pub(crate) fn resolve_aux_model_sampling_config(
return None;
}
}
if !account_login {
return None;
}
let hoshizukimio_bearer = session_key
.map(|s| s.to_owned())
.or_else(|| crate::agent::auth_method::read_hoshizukimio_api_key_env().ok())
@@ -4908,7 +4914,9 @@ pub(crate) fn resolve_web_search_sampling_config(
None,
None,
))
} else if model_id == crate::models::default_web_search_model() {
} else if Distribution::current().allows(Capability::RemoteFetch)
&& model_id == crate::models::default_web_search_model()
{
Some(resolve_hidden_default_web_search_sampling_config(
model_id,
session_key,

View File

@@ -124,11 +124,7 @@ impl MvpAgent {
);
cfg
}
None => {
let mut fallback = primary.clone();
fallback.model = slug;
fallback
}
None => primary.clone(),
};
let model = config.model.clone();
let client = OaiCompatClient::new(config).map_err(map_sampling_err_to_acp)?;
@@ -2217,7 +2213,10 @@ impl MvpAgent {
&self,
) -> hoshizukimio_mio_tools::implementations::mio_build::image_gen::ImageGenConfig {
use hoshizukimio_mio_tools::implementations::mio_build::image_gen::ImageGenConfig;
if self.sampling_config.borrow().api_key.is_none() {
if !hoshizukimio_mio_config::Distribution::current()
.allows(hoshizukimio_mio_config::Capability::RemoteFetch)
|| self.sampling_config.borrow().api_key.is_none()
{
return ImageGenConfig::Disabled;
}
crate::agent::media_tool_config::image_gen_config(
@@ -2247,7 +2246,10 @@ impl MvpAgent {
&self,
) -> hoshizukimio_mio_tools::implementations::mio_build::video_gen::VideoGenConfig {
use hoshizukimio_mio_tools::implementations::mio_build::video_gen::VideoGenConfig;
if self.sampling_config.borrow().api_key.is_none() {
if !hoshizukimio_mio_config::Distribution::current()
.allows(hoshizukimio_mio_config::Capability::RemoteFetch)
|| self.sampling_config.borrow().api_key.is_none()
{
return VideoGenConfig::Disabled;
}
crate::agent::media_tool_config::video_gen_config(

View File

@@ -223,8 +223,16 @@ def verify(binary, tui):
settings = root / "config.toml"
env = {key: value for key, value in os.environ.items()
if not key.upper().startswith(("MIO_", "HOSHIZUKIMIO_", "OTEL_"))
and key.upper() not in {"ALL_PROXY", "HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"}}
and key.upper() not in {
"ALL_PROXY", "HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY",
"HOME", "USERPROFILE", "CODEX_HOME", "CLAUDE_CONFIG_DIR",
"XDG_CONFIG_HOME", "XDG_DATA_HOME",
}}
fake_home = root / "home"
fake_home.mkdir()
env.update(
HOME=str(fake_home), USERPROFILE=str(fake_home),
XDG_CONFIG_HOME=str(fake_home / "config"), XDG_DATA_HOME=str(fake_home / "data"),
MIO_HOME=directory, MIO_SMOKE_KEY=KEY, TERM="xterm-256color",
HTTP_PROXY=proxy, HTTPS_PROXY=proxy, ALL_PROXY=proxy,
NO_PROXY="localhost,127.0.0.1",
@@ -265,18 +273,24 @@ def verify(binary, tui):
assert "smoke (default)" in run("models")
assert requests.empty(), "listing models contacted the model endpoint"
assert TEXT in run("-p", "Respond with the test phrase.")
assert not requests.empty(), backend
saw_inference = False
while not requests.empty():
method, path, headers, body = requests.get_nowait()
assert (method, path) == ("POST", ROUTES[backend]), (backend, method, path)
headers = {key.lower(): value for key, value in headers.items()}
if (method, path) == ("GET", "/"):
assert "authorization" not in headers and "x-api-key" not in headers, headers
continue
assert (method, path) == ("POST", ROUTES[backend]), (backend, method, path)
saw_inference = True
if backend == "messages":
assert headers.get("x-api-key") == KEY, headers
elif keyed:
assert headers.get("authorization") == f"Bearer {KEY}", headers
else:
assert not headers.get("authorization") and not headers.get("x-api-key"), headers
assert json.loads(body)["model"] == MODEL
actual_model = json.loads(body)["model"]
assert actual_model == MODEL, (backend, method, path, actual_model)
assert saw_inference, backend
assert unexpected.empty(), unexpected.get_nowait()
print(f"Passed {backend} {'with credentials' if keyed else 'without credentials'}")
@@ -291,7 +305,10 @@ def verify(binary, tui):
'env_key = "MIO_SMOKE_KEY"\nmax_retries = 0\n', encoding="utf-8",
)
run("-p", "check redirect", success=False)
assert not requests.empty()
sent = []
while not requests.empty():
sent.append(requests.get_nowait()[:2])
assert ("POST", "/redirect" + ROUTES["chat_completions"]) in sent, sent
assert unexpected.empty(), unexpected.get_nowait()
print("Verified inference does not follow an HTTP redirect")