Port the Mistral open weights and the GLM family

This commit is contained in:
Thorsten Sommer committed 2026-09-11 22:10:40 +02:00
1 parent 9c65ab6c62
commit ad3a25c80f
9 files changed
+215 -7

No files matched your search

@@ -0,0 +1,31 @@
using AIStudio.Provider;
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Microsoft;
/// <summary>
/// E5, the embedding models built on somebody else's weights.
/// </summary>
/// <remarks>
/// "e5-mistral-7b-instruct" is what made this a family of its own. It is an embedding model, and it
/// carries the name of the model it was trained from, so the Mistral rules answer for it and tell
/// it that it chats and calls functions. Saying which name means what it says is cheaper than
/// teaching every family whose weights somebody built an embedder from.
///
/// The E5 part is the whole statement: the rest of the name says nothing about what the model does.
/// </remarks>
public sealed class E5Family : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.MICROSOFT;
/// <inheritdoc />
public override ModelSource Source => new("https://huggingface.co/intfloat/e5-mistral-7b-instruct", new DateOnly(2026, 9, 11), "The app lists this under IProvider.GetEmbeddingModels, which is where the statement that it embeds comes from.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("e5").AsSegment()
.Capabilities(TEXT_INPUT | EMBEDDING)
.Kind(ModelKind.EMBEDDING);
}
@@ -0,0 +1,37 @@
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.Mistral;
/// <summary>
/// The Mistral models which carry no further family name: Mistral 7B, Mistral 3, and their kin.
/// </summary>
/// <remarks>
/// The open weights are where these live. Mistral's own API sells the named ranges -- Small,
/// Medium, Large -- while the plain checkpoints are the ones people run themselves, which is why
/// nothing here is dated: those names carry a size and a quantization instead of a release.
///
/// A substring, and it has to be one: this is the fallback of the whole range, and every family
/// with a name of its own beats it by saying more. What it must not do is claim Ministral or
/// Magistral, and it does not -- neither of those two names contains "mistral".
/// </remarks>
public sealed class MistralFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.MISTRAL_AI;
/// <inheritdoc />
public override ModelSource Source => new("https://docs.mistral.ai/getting-started/models/weights/", new DateOnly(2026, 9, 11), "Ported unchanged from the Mistral block of ProviderExtensions.OpenSource.cs: its default answer, and the rule for the 3 line.");
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder)
{
builder.Rule("mistral").AsSubstring()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API);
// The 3 line reads images and thinks when it is asked to:
builder.Rule("mistral-3").AsSegment().Inherits()
.Capabilities(MULTIPLE_IMAGE_INPUT)
.Reasoning(ReasoningSupport.OPTIONAL);
}
}
@@ -49,7 +49,9 @@ public static class MistralReleases
/// <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.
/// names carry no release date, so they are mapped onto the release they stand for. Ollama
/// leaves the separator out altogether for the Small checkpoints, which is a third spelling of
/// the same statement.
///
/// 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
@@ -71,6 +73,11 @@ public static class MistralReleases
("mistral-small-3.1", 2503),
("mistral-small-3-1", 2503),
("mistral-small-3", 2501),
("mistral-small4", 2603),
("mistral-small3.2", 2506),
("mistral-small3.1", 2503),
("mistral-small3", 2501),
];
/// <summary>
@@ -5,6 +5,12 @@ namespace AIStudio.Models.Mistral;
/// <summary>
/// Mistral Small, which gained images with 3.1 and reasoning with 4.
/// </summary>
/// <remarks>
/// The one family of the range whose name arrives glued to its version: Ollama publishes the open
/// weights as "mistral-small3.1" and "mistral-small3.2", without the separator Mistral's own API
/// writes. A substring covers both spellings, and it stays specific enough that nothing else in the
/// range can be mistaken for it.
/// </remarks>
public sealed class MistralSmallFamily : MistralReleaseDatedFamily
{
/// <inheritdoc />
@@ -21,7 +27,7 @@ public sealed class MistralSmallFamily : MistralReleaseDatedFamily
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder) =>
builder.Rule("mistral-small").AsSegment()
builder.Rule("mistral-small").AsSubstring()
.Capabilities(WHAT_THEY_COULD_ALWAYS_DO)
.Apis(CHAT_COMPLETION_API);
}
@@ -0,0 +1,82 @@
using AIStudio.Models.Matching;
using static AIStudio.Provider.Capability;
namespace AIStudio.Models.ZAI;
/// <summary>
/// GLM, from Z AI.
/// </summary>
/// <remarks>
/// Two things about these names need saying. Z AI writes the version with a dot, but Mistral serves
/// the same models as "glm-5-2" and "zai-glm-5-2", so each generation is stated in both spellings.
/// And a vision model is marked by a "v" glued to the version number -- glm-4v, glm-4.1v, glm-4.5v
/// -- which is not a name part and therefore not something a pattern can ask about. That is what
/// the refinement below is for.
///
/// Looking for a bare "v" anywhere, which the previous rules started out doing, calls every
/// quantized build a vision model: "nvfp4" carries one, and so does the name of more than one
/// inference provider. The digit in front is what makes it a version marker.
/// </remarks>
public sealed class GlmFamily : ModelFamily
{
/// <inheritdoc />
public override ModelVendor Vendor => ModelVendor.Z_AI;
/// <inheritdoc />
public override ModelSource Source => new("https://huggingface.co/zai-org", new DateOnly(2026, 9, 11), "Ported unchanged from the Z AI block of ProviderExtensions.OpenSource.cs.");
/// <inheritdoc />
public override ModelProfile Refine(in ModelId id, in ModelProfile selected)
{
if (!MarksAVisionModel(id.Normalized.AsSpan()))
return selected;
return selected with { Capabilities = selected.Capabilities | MULTIPLE_IMAGE_INPUT };
}
/// <inheritdoc />
protected override void Declare(ModelFamilyBuilder builder)
{
// Every other GLM thinks when the request asks it to:
builder.Rule("glm").AsSubstring()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API)
.Reasoning(ReasoningSupport.OPTIONAL);
// The 4 line answers straight away:
builder.Rule("glm-4").AsSegment()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API);
// 5.2 thinks unless it is told not to:
builder.Rule("glm-5.2").AsSegment()
.Capabilities(TEXT_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API)
.Reasoning(ReasoningSupport.ON_BY_DEFAULT);
builder.Rule("glm-5-2").AsSegment().Inherits();
// 5.3 thinks whatever it is told: only the effort can be lowered, not the thinking itself.
builder.Rule("glm-5.3").AsSegment()
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
.Apis(CHAT_COMPLETION_API)
.Reasoning(ReasoningSupport.ALWAYS);
builder.Rule("glm-5-3").AsSegment().Inherits();
}
/// <summary>
/// Whether the version number of this name is followed by the vision marker.
/// </summary>
/// <param name="modelName">The normalized model name.</param>
/// <returns>True, when a "v" sits directly behind a digit.</returns>
private static bool MarksAVisionModel(ReadOnlySpan<char> modelName)
{
for (var index = 1; index < modelName.Length; index++)
if (modelName[index] is 'v' && char.IsAsciiDigit(modelName[index - 1]))
return true;
return false;
}
}