Port the Mistral families, including the release date logic

This commit is contained in:
Thorsten Sommer committed 2026-09-11 20:33:16 +02:00
1 parent 430867089e
commit 31a1aec69c
14 files changed
+568

No files matched your search

@@ -0,0 +1,27 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Codestral, the Mistral models for writing code.
/// </summary>
/// <remarks>
/// The previous rules never named it. Its name contains neither "mistral" nor any of the other
/// words the Mistral block looked for, so it walked past every rule and reached the answer meant
/// for everything nobody had written one for. That answer happened to describe it correctly, which
/// is why nothing looked wrong -- and is exactly the situation this rebuild is meant to end.
/// </remarks>
public sealed class CodestralFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.MISTRAL_AI;
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/models_overview/", new DateOnly(2026, 9, 11), "The answer the previous rules gave it through their fallback: text in, text out, tool calling.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("codestral").AsSegment()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API);
}
@@ -0,0 +1,22 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Magistral, the Mistral models which always think before they answer.
/// </summary>
public sealed class MagistralFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.MISTRAL_AI;
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/models_overview/", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.OpenSource.cs: images, tool calling, and thinking which cannot be switched off.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("magistral").AsSegment()
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API)
.Reasoning(ReasoningSupport.ALWAYS);
}
@@ -0,0 +1,33 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Ministral, the small ones, which see from the third generation on and never reason.
/// </summary>
/// <remarks>
/// The name is one letter away from the rest of the range and shares no name part with it, which
/// the previous rules had to say out loud: the Ministral check sat above the Mistral block because
/// "ministral" does not contain "mistral". Here that is not a question anybody has to ask -- the
/// rules answer for the name part they were written for and for no other.
/// </remarks>
public sealed class MinistralFamily : MistralReleaseDatedFamily
{
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/models_overview/", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Mistral.cs: images from Ministral 3 on, and no reasoning in any release.");
/// <inheritdoc />
protected override int VisionSince => 2512;
/// <inheritdoc />
protected override int ReasoningSince => MistralReleases.NEVER;
/// <inheritdoc />
protected override int LatestRelease => 2512;
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("ministral").AsSegment()
.Capabilities(WHAT_THEY_COULD_ALWAYS_DO)
.Apis(CHAT_COMPLETION_API);
}
@@ -0,0 +1,27 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Mistral Large, which learned to see and to think with the same release.
/// </summary>
public sealed class MistralLargeFamily : MistralReleaseDatedFamily
{
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/models_overview/", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Mistral.cs: images and reasoning from Mistral Large 3 on.");
/// <inheritdoc />
protected override int VisionSince => 2512;
/// <inheritdoc />
protected override int ReasoningSince => 2512;
/// <inheritdoc />
protected override int LatestRelease => 2512;
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("mistral-large").AsSegment()
.Capabilities(WHAT_THEY_COULD_ALWAYS_DO)
.Apis(CHAT_COMPLETION_API);
}
@@ -0,0 +1,27 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Mistral Medium, which could see for almost a year before it could think.
/// </summary>
public sealed class MistralMediumFamily : MistralReleaseDatedFamily
{
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/models_overview/", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Mistral.cs: images from Mistral Medium 3 on, reasoning from Mistral Medium 3.5 on.");
/// <inheritdoc />
protected override int VisionSince => 2505;
/// <inheritdoc />
protected override int ReasoningSince => 2604;
/// <inheritdoc />
protected override int LatestRelease => 2604;
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("mistral-medium").AsSegment()
.Capabilities(WHAT_THEY_COULD_ALWAYS_DO)
.Apis(CHAT_COMPLETION_API);
}
@@ -0,0 +1,25 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Mistral NeMo, the open model Mistral built with NVIDIA.
/// </summary>
/// <remarks>
/// Mistral's own API serves it as "open-mistral-nemo", the hubs as "mistral-nemo". Whole name
/// parts cover both, which is why nothing here cares which of the two arrived.
/// </remarks>
public sealed class MistralNemoFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.MISTRAL_AI;
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/models_overview/", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.OpenSource.cs: text in, text out, tool calling.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("mistral-nemo").AsSegment()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API);
}
@@ -0,0 +1,59 @@
using AIStudio.Models.Matching;
using AIStudio.Provider;
namespace AIStudio.Models.Mistral;
/// <summary>
/// A Mistral family whose abilities depend on when the model was released rather than on its name.
/// </summary>
/// <remarks>
/// This is the case the refinement exists for. Four Mistral families gained image input and
/// reasoning at some release and carried the same name before and after, so no pattern can tell
/// the two apart: mistral-large-2411 and mistral-large-2512 differ in what they can do and in
/// nothing a rule could match on.
///
/// So the rule states what the family has always been able to do, and each family says from which
/// release on it gained the rest. Everything shared sits here; a family below is three numbers and
/// one rule.
/// </remarks>
public abstract class MistralReleaseDatedFamily : ModelFamily
{
/// <summary>
/// What every one of these families could do from its very first release.
/// </summary>
protected const Capability WHAT_THEY_COULD_ALWAYS_DO = Capability.TEXT_INPUT | Capability.TEXT_OUTPUT | Capability.FUNCTION_CALLING;
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.MISTRAL_AI;
/// <summary>
/// The release from which this family accepts images.
/// </summary>
protected abstract int VisionSince { get; }
/// <summary>
/// The release from which this family can reason, or never.
/// </summary>
protected abstract int ReasoningSince { get; }
/// <summary>
/// The release this family's "latest" alias currently points at.
/// </summary>
/// <remarks>
/// Mistral moves the alias on with every release, so it has to behave like the release it
/// resolves to instead of carrying rules of its own.
/// </remarks>
protected abstract int LatestRelease { get; }
/// <inheritdoc />
public override ModelProfile Refine(in ModelId id, in ModelProfile selected)
{
var release = MistralReleases.Of(id, this.LatestRelease);
return selected with
{
Capabilities = release >= this.VisionSince ? selected.Capabilities | Capability.MULTIPLE_IMAGE_INPUT : selected.Capabilities,
Reasoning = release >= this.ReasoningSince ? ReasoningSupport.OPTIONAL : selected.Reasoning,
};
}
}
@@ -0,0 +1,132 @@
using AIStudio.Models.Matching;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Reads the release a Mistral model belongs to out of its name.
/// </summary>
/// <remarks>
/// Mistral names its models after the month they came out: mistral-large-2512 is Mistral Large 3
/// from December 2025. The marketing version lives in the marketing name only, so a rule written
/// against it would miss nearly every model the API actually serves. What a family can state is
/// therefore not "this model reads images" but "this family reads images from this release on",
/// and that is a calculation, not a pattern -- which is what the families do in Refine.
/// </remarks>
public static class MistralReleases
{
/// <summary>
/// A threshold no release can ever reach, for a family which never gained the ability at all.
/// </summary>
public const int NEVER = int.MaxValue;
/// <summary>
/// What a name says when it carries no release at all.
/// </summary>
/// <remarks>
/// Nothing is granted for it. That is the safe direction: offering an ability the model does
/// not have makes the request fail, while a missing one can be handed back by a person through
/// the expert settings.
/// </remarks>
public const int UNKNOWN = 0;
/// <summary>
/// How many digits a release is written with.
/// </summary>
private const int RELEASE_LENGTH = 4;
/// <summary>
/// Mistral released its first date-named model in 2023.
/// </summary>
/// <remarks>
/// Anything below that is not a release date but a parameter count or a context size which
/// happens to have four digits.
/// </remarks>
private const int FIRST_RELEASE_YEAR = 23;
/// <summary>
/// The releases the marketing versions stand for.
/// </summary>
/// <remarks>
/// Mistral serves some models under their marketing version as well, and writes the version
/// separator both ways: mistral-medium-3.5 and mistral-medium-3-5 are the same model. Those
/// names carry no release date, so they are mapped onto the release they stand for.
///
/// The order matters, and it is the one place in this rebuild where it still does: these are
/// read as plain text rather than as patterns, so "mistral-medium-3" would answer for
/// "mistral-medium-3.5" if it came first.
/// </remarks>
private static readonly (string VersionName, int Release)[] VERSION_NAMES =
[
("mistral-large-3", 2512),
("mistral-medium-3.5", 2604),
("mistral-medium-3-5", 2604),
("mistral-medium-3.1", 2508),
("mistral-medium-3-1", 2508),
("mistral-medium-3", 2505),
("mistral-small-4", 2603),
("mistral-small-3.2", 2506),
("mistral-small-3-2", 2506),
("mistral-small-3.1", 2503),
("mistral-small-3-1", 2503),
("mistral-small-3", 2501),
];
/// <summary>
/// The release a model name belongs to.
/// </summary>
/// <param name="id">The model name.</param>
/// <param name="latestRelease">The release this family's "latest" alias currently points at.</param>
/// <returns>The release as YYMM, or unknown.</returns>
public static int Of(in ModelId id, int latestRelease)
{
// The "latest" alias always points at the newest release of its family:
if (id.ContainsSegments("latest"))
return latestRelease;
foreach (var (versionName, release) in VERSION_NAMES)
if (id.ContainsText(versionName))
return release;
return ReadFrom(id.Normalized.AsSpan());
}
/// <summary>
/// Reads the four-digit release out of a name.
/// </summary>
/// <remarks>
/// The block has to be exactly four digits long and has to read as a plausible year and month.
/// Without that, the size of a model would be mistaken for its release: ministral-14b-2512 has
/// to resolve to 2512 and not to anything the "14b" part could be read as.
/// </remarks>
/// <param name="modelName">The normalized model name.</param>
/// <returns>The release as YYMM, or unknown.</returns>
private static int ReadFrom(ReadOnlySpan<char> modelName)
{
for (var index = 0; index + RELEASE_LENGTH <= modelName.Length; index++)
{
// A digit next to the block means the block is longer than four digits:
if (index > 0 && char.IsAsciiDigit(modelName[index - 1]))
continue;
if (index + RELEASE_LENGTH < modelName.Length && char.IsAsciiDigit(modelName[index + RELEASE_LENGTH]))
continue;
var candidate = modelName.Slice(index, RELEASE_LENGTH);
if (!char.IsAsciiDigit(candidate[0]) || !char.IsAsciiDigit(candidate[1]) ||
!char.IsAsciiDigit(candidate[2]) || !char.IsAsciiDigit(candidate[3]))
continue;
var release = int.Parse(candidate);
var year = release / 100;
var month = release % 100;
if (year < FIRST_RELEASE_YEAR || month is < 1 or > 12)
continue;
return release;
}
return UNKNOWN;
}
}
@@ -0,0 +1,26 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Mistral Saba, the regional model for the Middle East and South Asia.
/// </summary>
/// <remarks>
/// The one Mistral in this range which calls no tools at all. It needs its own rule for that
/// reason alone: without it, the length of "mistral-small" and "mistral-large" would not matter,
/// but the shape they share would be handed to a model which does not have it.
/// </remarks>
public sealed class MistralSabaFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.MISTRAL_AI;
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/models_overview/", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Mistral.cs: text in, text out, and nothing else.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("mistral-saba").AsSegment()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT)
.Apis(CHAT_COMPLETION_API);
}
@@ -0,0 +1,27 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Mistral Small, which gained images with 3.1 and reasoning with 4.
/// </summary>
public sealed class MistralSmallFamily : MistralReleaseDatedFamily
{
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/models_overview/", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Mistral.cs: images from Mistral Small 3.1 on, reasoning from Mistral Small 4 on.");
/// <inheritdoc />
protected override int VisionSince => 2503;
/// <inheritdoc />
protected override int ReasoningSince => 2603;
/// <inheritdoc />
protected override int LatestRelease => 2603;
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("mistral-small").AsSegment()
.Capabilities(WHAT_THEY_COULD_ALWAYS_DO)
.Apis(CHAT_COMPLETION_API);
}
@@ -0,0 +1,24 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Pixtral, the Mistral models built to look at pictures.
/// </summary>
/// <remarks>
/// They read images from the first release, so nothing here depends on a date.
/// </remarks>
public sealed class PixtralFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.MISTRAL_AI;
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/models_overview/", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Mistral.cs: images in every release.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("pixtral").AsSegment()
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API);
}
@@ -0,0 +1,26 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// Voxtral, the Mistral models which listen.
/// </summary>
/// <remarks>
/// They take speech as input and answer in text, which makes them neither a chat model nor a
/// transcription model but something in between: they understand what was said rather than only
/// writing it down.
/// </remarks>
public sealed class VoxtralFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.MISTRAL_AI;
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/models_overview/", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.OpenSource.cs: speech in, text out, tool calling.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("voxtral").AsSegment()
.Capabilities(TEXT_INPUT | SPEECH_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API);
}