modelplease 0.1.0

Provider-neutral language model client with streaming, media, capabilities, and optional provider integrations
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
// Copyright 2026 Thomas Santerre and Moderately AI Inc.
//
// SPDX-License-Identifier: MIT OR Apache-2.0

use std::{
    collections::{BTreeMap, HashMap},
    sync::LazyLock,
};

use enumset::enum_set;

use crate::{
    anthropic_wire::{mantle_anthropic_adaptive_reasoning, mantle_anthropic_haiku_reasoning},
    capabilities::{
        MediaKind, MediaSupport, ReasoningCapability, ReasoningMode, ReasoningParamConflicts,
    },
    config::ReasoningEffort,
    media::SourceKind,
};

/// Per-model capability data for the Mantle catalog.
///
/// Wraps the same fields as the other providers' tables, populated from each model's AWS
/// model-card page. Entries are conservative on reasoning + media (declared only when documented),
/// because [`LanguageModelProvider::validate_request`] uses them to reject ill-formed requests
/// *before* they hit the wire. Wrong-but-too-permissive entries surface as Mantle 400s; wrong-but-
/// too-restrictive entries reject calls that would have succeeded. When uncertain we lean
/// permissive on context_window / json_schema (informational) and restrictive on reasoning /
/// media (enforced).
#[derive(Debug, Clone)]
pub(super) struct MantleModelCapabilities {
    pub(super) context_window: u32,
    pub(super) supports_streaming: bool,
    pub(super) supports_json_schema: bool,
    pub(super) reasoning: Option<ReasoningCapability>,
    pub(super) media_support: BTreeMap<MediaKind, MediaSupport>,
}

// --- Media support helpers per modality ---

/// Image support shared by every vision-capable Chat Completions model on Mantle.
///
/// Same sources OpenAI Chat Completions accepts (`Url` + `InlineBytes` as a `data:` URI), the
/// same subtype list, and the same 20 MB local size cap — those are the values
/// [`crate::openai::translate_part_for_openai`] emits, and Mantle's surface accepts the same
/// shapes since it speaks the OpenAI wire format. If a specific Mantle vision model publishes a
/// tighter constraint we'll split into per-family helpers; for now this is the conservative
/// default.
const fn mantle_image_support() -> MediaSupport {
    MediaSupport {
        sources: enum_set!(SourceKind::Url | SourceKind::InlineBytes),
        formats: &["png", "jpeg", "webp", "gif"],
        max_bytes: Some(20 * 1024 * 1024),
        max_count_per_message: None,
    }
}

/// Audio support for the Voxtral mini / small models on Mantle. Per AWS Voxtral docs the model
/// accepts `audio/wav`, `audio/mpeg`, `audio/mp3`, `audio/flac` with a 25 MB inline-bytes cap.
/// `Url` is not exposed at the Chat Completions content-part layer for audio, so InlineBytes is
/// the only source kind here.
const fn mantle_voxtral_audio_support() -> MediaSupport {
    MediaSupport {
        sources: enum_set!(SourceKind::InlineBytes),
        formats: &["wav", "mpeg", "mp3", "flac"],
        max_bytes: Some(25 * 1024 * 1024),
        max_count_per_message: None,
    }
}

// --- Reasoning capability constructors per family ---

/// OpenAI reasoning models on Mantle (gpt-oss-* via Chat Completions, gpt-5.* via Responses) all
/// reject `temperature` while reasoning is active. `top_p` has no documented restriction.
const fn openai_reasoning_conflicts() -> ReasoningParamConflicts {
    ReasoningParamConflicts {
        temperature_forbidden: true,
        top_k_forbidden: false,
        top_p_allowed_range: None,
    }
}

/// `ReasoningCapability` for `openai.gpt-5.{4,5}` — full 5-value effort enum (none / low /
/// medium / high / xhigh) per OpenAI's published spec. Routed via the Responses surface (phase 6).
const fn mantle_gpt5_reasoning() -> ReasoningCapability {
    ReasoningCapability {
        supported_modes: enum_set!(ReasoningMode::Adaptive),
        supported_efforts: enum_set!(
            ReasoningEffort::None
                | ReasoningEffort::Low
                | ReasoningEffort::Medium
                | ReasoningEffort::High
                | ReasoningEffort::XHigh
        ),
        manual_budget_range: None,
        conflicts: openai_reasoning_conflicts(),
        sampling_params_removed: false,
    }
}

/// `ReasoningCapability` for OpenAI's open-weight `gpt-oss-*` family on Mantle — `reasoning_effort`
/// in `{low, medium, high}` only (no `xhigh`, no `none`-as-effort — `Off` covers that path).
const fn mantle_gpt_oss_reasoning() -> ReasoningCapability {
    ReasoningCapability {
        supported_modes: enum_set!(ReasoningMode::Adaptive),
        supported_efforts: enum_set!(
            ReasoningEffort::Low | ReasoningEffort::Medium | ReasoningEffort::High
        ),
        manual_budget_range: None,
        conflicts: openai_reasoning_conflicts(),
        sampling_params_removed: false,
    }
}

/// `ReasoningCapability` for the generic open-weight thinking-mode families — DeepSeek-R1-style,
/// Qwen3 thinking, MiniMax M2.x, Kimi K2 thinking, Nemotron, Magistral. Accept the OpenAI-shape
/// `reasoning_effort` field with `{low, medium, high}`. Conflicts are conservative (forbid
/// `temperature` when reasoning is on, matching the OpenAI-shape Chat Completions surface).
const fn mantle_open_thinking_reasoning() -> ReasoningCapability {
    ReasoningCapability {
        supported_modes: enum_set!(ReasoningMode::Adaptive),
        supported_efforts: enum_set!(
            ReasoningEffort::Low | ReasoningEffort::Medium | ReasoningEffort::High
        ),
        manual_budget_range: None,
        conflicts: openai_reasoning_conflicts(),
        sampling_params_removed: false,
    }
}

/// Static capability table for the Mantle catalog. Populated from each model's AWS model-card
/// page; a live `GET /v1/models` on 2026-06-04 returned 41–42 models per
/// region — we ship a row for each. Unknown IDs returned by upstream fire a one-time
/// `tracing::warn!` per cache fill (see [`fetch_and_merge_models`](Self::fetch_and_merge_models)).
///
/// Phase 3 ships text-only entries; phase 4 adds the per-model `media_support` rows for the
/// vision-capable families (Qwen3-VL, Palmyra-Vision-7B, Gemma 3, Nemotron-12B-VL) and audio
/// for the Voxtral family.
pub(super) static MODEL_CAPABILITIES: LazyLock<HashMap<&'static str, MantleModelCapabilities>> =
    LazyLock::new(|| {
        let mut m = HashMap::new();

        // --- OpenAI frontier (Responses surface, phase 6) ---
        for id in ["openai.gpt-5.5", "openai.gpt-5.4"] {
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 1_000_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: Some(mantle_gpt5_reasoning()),
                    media_support: BTreeMap::new(),
                },
            );
        }
        // Dated variants — same caps as their base id.
        for id in ["openai.gpt-5.5-2026-04-23", "openai.gpt-5.4-2026-03-05"] {
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 1_000_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: Some(mantle_gpt5_reasoning()),
                    media_support: BTreeMap::new(),
                },
            );
        }

        // --- OpenAI open-weight (Chat Completions) ---
        for id in ["openai.gpt-oss-120b", "openai.gpt-oss-20b"] {
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 128_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: Some(mantle_gpt_oss_reasoning()),
                    media_support: BTreeMap::new(),
                },
            );
        }
        // Safeguard is a classifier — no reasoning surface.
        for id in [
            "openai.gpt-oss-safeguard-120b",
            "openai.gpt-oss-safeguard-20b",
        ] {
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 128_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: None,
                    media_support: BTreeMap::new(),
                },
            );
        }

        // --- Anthropic Claude on Mantle (Messages surface, phase 5) ---
        // Per AWS Mythos docs, Mantle's Messages path does NOT support prompt caching (callers
        // wanting caching go through bedrock-runtime / Converse). Media support lives in phase 4
        // with the rest of the vision/document content-part wiring.
        m.insert(
            "anthropic.claude-haiku-4-5",
            MantleModelCapabilities {
                context_window: 200_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: Some(mantle_anthropic_haiku_reasoning()),
                media_support: BTreeMap::new(),
            },
        );
        m.insert(
            "anthropic.claude-opus-4-7",
            MantleModelCapabilities {
                context_window: 1_000_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: Some(mantle_anthropic_adaptive_reasoning()),
                media_support: BTreeMap::new(),
            },
        );
        m.insert(
            "anthropic.claude-opus-4-8",
            MantleModelCapabilities {
                context_window: 1_000_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: Some(mantle_anthropic_adaptive_reasoning()),
                media_support: BTreeMap::new(),
            },
        );
        m.insert(
            "anthropic.claude-mythos-preview",
            MantleModelCapabilities {
                context_window: 1_000_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: Some(mantle_anthropic_adaptive_reasoning()),
                media_support: BTreeMap::new(),
            },
        );

        // --- DeepSeek ---
        // V3.1 is a hybrid reasoning model (R1-style on demand). V3.2 is a non-reasoning variant.
        m.insert(
            "deepseek.v3.1",
            MantleModelCapabilities {
                context_window: 128_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: Some(mantle_open_thinking_reasoning()),
                media_support: BTreeMap::new(),
            },
        );
        m.insert(
            "deepseek.v3.2",
            MantleModelCapabilities {
                context_window: 128_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: None,
                media_support: BTreeMap::new(),
            },
        );

        // --- Mistral ---
        // Devstral (coding), Mistral-Large-3, Ministral 3-* (text), Voxtral mini/small (text +
        // audio — audio support lands in phase 4). Magistral-small is a reasoning model.
        m.insert(
            "mistral.devstral-2-123b",
            MantleModelCapabilities {
                context_window: 256_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: None,
                media_support: BTreeMap::new(),
            },
        );
        m.insert(
            "mistral.magistral-small-2509",
            MantleModelCapabilities {
                context_window: 128_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: Some(mantle_open_thinking_reasoning()),
                media_support: BTreeMap::new(),
            },
        );
        m.insert(
            "mistral.mistral-large-3-675b-instruct",
            MantleModelCapabilities {
                context_window: 128_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: None,
                media_support: BTreeMap::new(),
            },
        );
        for id in [
            "mistral.ministral-3-3b-instruct",
            "mistral.ministral-3-8b-instruct",
            "mistral.ministral-3-14b-instruct",
        ] {
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 128_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: None,
                    media_support: BTreeMap::new(),
                },
            );
        }
        // Voxtral — audio-input chat models, 25 MB inline-bytes cap on wav/mp3/mpeg/flac.
        for id in [
            "mistral.voxtral-mini-3b-2507",
            "mistral.voxtral-small-24b-2507",
        ] {
            let mut media = BTreeMap::new();
            media.insert(MediaKind::Audio, mantle_voxtral_audio_support());
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 32_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: None,
                    media_support: media,
                },
            );
        }

        // --- Google Gemma 3 (vision-capable text+image chat models) ---
        for id in [
            "google.gemma-3-4b-it",
            "google.gemma-3-12b-it",
            "google.gemma-3-27b-it",
        ] {
            let mut media = BTreeMap::new();
            media.insert(MediaKind::Image, mantle_image_support());
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 128_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: None,
                    media_support: media,
                },
            );
        }

        // --- Qwen3 ---
        // Text-only Qwen3 variants share text-only media. qwen3-vl-* is the vision-capable
        // variant — declares Image media_support.
        for id in [
            "qwen.qwen3-32b",
            "qwen.qwen3-235b-a22b-2507",
            "qwen.qwen3-next-80b-a3b-instruct",
            "qwen.qwen3-coder-30b-a3b-instruct",
            "qwen.qwen3-coder-480b-a35b-instruct",
            "qwen.qwen3-coder-next",
        ] {
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 128_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: Some(mantle_open_thinking_reasoning()),
                    media_support: BTreeMap::new(),
                },
            );
        }
        {
            let mut media = BTreeMap::new();
            media.insert(MediaKind::Image, mantle_image_support());
            m.insert(
                "qwen.qwen3-vl-235b-a22b-instruct",
                MantleModelCapabilities {
                    context_window: 128_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: Some(mantle_open_thinking_reasoning()),
                    media_support: media,
                },
            );
        }

        // --- NVIDIA Nemotron ---
        // Text-only nano-9b / nano-3-30b / super-3-120b. nano-12b is the vision-capable (VL)
        // variant.
        for id in [
            "nvidia.nemotron-nano-9b-v2",
            "nvidia.nemotron-nano-3-30b",
            "nvidia.nemotron-super-3-120b",
        ] {
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 128_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: Some(mantle_open_thinking_reasoning()),
                    media_support: BTreeMap::new(),
                },
            );
        }
        {
            let mut media = BTreeMap::new();
            media.insert(MediaKind::Image, mantle_image_support());
            m.insert(
                "nvidia.nemotron-nano-12b-v2",
                MantleModelCapabilities {
                    context_window: 128_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: Some(mantle_open_thinking_reasoning()),
                    media_support: media,
                },
            );
        }

        // --- MiniMax M2 family ---
        for id in [
            "minimax.minimax-m2",
            "minimax.minimax-m2.1",
            "minimax.minimax-m2.5",
        ] {
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 200_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: Some(mantle_open_thinking_reasoning()),
                    media_support: BTreeMap::new(),
                },
            );
        }

        // --- Moonshot Kimi ---
        // K2-thinking is the reasoning-mode variant; K2.5 is the standard chat model with toggle.
        m.insert(
            "moonshotai.kimi-k2-thinking",
            MantleModelCapabilities {
                context_window: 200_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: Some(mantle_open_thinking_reasoning()),
                media_support: BTreeMap::new(),
            },
        );
        m.insert(
            "moonshotai.kimi-k2.5",
            MantleModelCapabilities {
                context_window: 256_000,
                supports_streaming: true,
                supports_json_schema: true,
                reasoning: Some(mantle_open_thinking_reasoning()),
                media_support: BTreeMap::new(),
            },
        );

        // --- Z.AI GLM ---
        // Reasoning support not documented at parity with the open-thinking family yet — leave
        // `reasoning: None` until verified. Wrong-too-permissive here is worse than wrong-too-
        // restrictive (we'd reject valid Adaptive requests vs. the model just ignoring the field).
        for id in [
            "zai.glm-4.6",
            "zai.glm-4.7",
            "zai.glm-4.7-flash",
            "zai.glm-5",
        ] {
            m.insert(
                id,
                MantleModelCapabilities {
                    context_window: 128_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: None,
                    media_support: BTreeMap::new(),
                },
            );
        }

        // --- Writer Palmyra-Vision ---
        // Vision-capable text+image chat model. No reasoning surface.
        {
            let mut media = BTreeMap::new();
            media.insert(MediaKind::Image, mantle_image_support());
            m.insert(
                "writer.palmyra-vision-7b",
                MantleModelCapabilities {
                    context_window: 128_000,
                    supports_streaming: true,
                    supports_json_schema: true,
                    reasoning: None,
                    media_support: media,
                },
            );
        }

        m
    });