mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-09-27 03:13:37 +00:00
Port the Alibaba Cloud families and refuse ambiguous rule inheritance
This commit is contained in:
parent
31a1aec69c
commit
5905f074b6
@ -0,0 +1,29 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
using static AIStudio.Provider.Capability;
|
||||
|
||||
namespace AIStudio.Models.Alibaba;
|
||||
|
||||
/// <summary>
|
||||
/// Alibaba's embedding models, which turn text into a vector and answer nothing.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The previous rules answered for these with the Model Studio default and told them they call
|
||||
/// functions. The prefix is Alibaba's own: the app filters the catalog by "text-embedding-" to find
|
||||
/// them, which is also why the rule may be written that broadly -- bound to this provider, it can
|
||||
/// only ever meet the models Alibaba names that way.
|
||||
/// </remarks>
|
||||
public sealed class ModelStudioEmbeddingFamily : ModelFamily
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override ModelVendor Vendor => ModelVendor.ALIBABA;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ModelSource Source => new("https://www.alibabacloud.com/help/en/model-studio/embedding", new DateOnly(2026, 9, 11), "Provider/AlibabaCloud/ProviderAlibabaCloud.cs adds these in GetEmbeddingModels and filters the catalog by the prefix \"text-embedding-\".");
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Declare(ModelFamilyBuilder builder) =>
|
||||
builder.Rule("text-embedding").AsPrefix().OnlyOn(LLMProviders.ALIBABA_CLOUD)
|
||||
.Capabilities(TEXT_INPUT | EMBEDDING)
|
||||
.Kind(ModelKind.EMBEDDING);
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
using static AIStudio.Provider.Capability;
|
||||
|
||||
namespace AIStudio.Models.Alibaba;
|
||||
|
||||
/// <summary>
|
||||
/// QVQ, the thinking-only model which also looks at pictures.
|
||||
/// </summary>
|
||||
public sealed class ModelStudioQvqFamily : ModelFamily
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override ModelVendor Vendor => ModelVendor.ALIBABA;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ModelSource Source => new("https://www.alibabacloud.com/help/en/model-studio/models", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Alibaba.cs: images in, thinking which cannot be switched off, and no tools.");
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Declare(ModelFamilyBuilder builder) =>
|
||||
builder.Rule("qvq").AsSegment().OnlyOn(LLMProviders.ALIBABA_CLOUD)
|
||||
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | TEXT_OUTPUT)
|
||||
.Apis(CHAT_COMPLETION_API)
|
||||
.Reasoning(ReasoningSupport.ALWAYS);
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
using static AIStudio.Provider.Capability;
|
||||
|
||||
namespace AIStudio.Models.Alibaba;
|
||||
|
||||
/// <summary>
|
||||
/// The Qwen models Alibaba Cloud Model Studio serves.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Everything in this folder is bound to Alibaba Cloud, and that is the point of it. Model Studio
|
||||
/// sells commercial models -- qwen-max, qwen3.7-max, qwq-plus -- which carry the family names of
|
||||
/// the open weights without being them, and it answers differently for several names the open
|
||||
/// weights share with it. The old rules kept the two apart by having two functions; here they are
|
||||
/// kept apart by saying which provider a rule speaks for.
|
||||
///
|
||||
/// The first rule is the catalog's own fallback, and it is written as a plain substring on purpose:
|
||||
/// a substring is the weakest thing a rule can be, so every other rule here beats it without anyone
|
||||
/// arranging that. It also has to be one, because "qwen2.5-72b-instruct" does not contain "qwen" as
|
||||
/// a whole name part -- the version grows straight out of the family name.
|
||||
/// </remarks>
|
||||
public sealed class ModelStudioQwenFamily : ModelFamily
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override ModelVendor Vendor => ModelVendor.ALIBABA;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ModelSource Source => new("https://www.alibabacloud.com/help/en/model-studio/models", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Alibaba.cs, which follow Alibaba's own list of models that call functions.");
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Declare(ModelFamilyBuilder builder)
|
||||
{
|
||||
builder.Rule("qwen").AsSubstring().OnlyOn(LLMProviders.ALIBABA_CLOUD)
|
||||
.Capabilities(TEXT_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
|
||||
.Apis(CHAT_COMPLETION_API);
|
||||
|
||||
// Qwen 3 thinks when asked to:
|
||||
builder.Rule("qwen3").AsPrefix().OnlyOn(LLMProviders.ALIBABA_CLOUD).Inherits()
|
||||
.Reasoning(ReasoningSupport.OPTIONAL);
|
||||
|
||||
builder.Rule("qwen3.5").AsPrefix().OnlyOn(LLMProviders.ALIBABA_CLOUD).InheritsFrom("qwen3")
|
||||
.Capabilities(MULTIPLE_IMAGE_INPUT);
|
||||
|
||||
builder.Rule("qwen3.6").AsPrefix().OnlyOn(LLMProviders.ALIBABA_CLOUD).InheritsFrom("qwen3")
|
||||
.Capabilities(MULTIPLE_IMAGE_INPUT | VIDEO_INPUT)
|
||||
.Reasoning(ReasoningSupport.ALWAYS);
|
||||
|
||||
//
|
||||
// Qwen 3.7 thinks unless it is told not to, and it started out reading nothing but text.
|
||||
// Vision arrived in the middle of the series, so only the June snapshot may be told that
|
||||
// it sees: the rolling max alias still answers as the May one.
|
||||
//
|
||||
builder.Rule("qwen3.7").AsPrefix().OnlyOn(LLMProviders.ALIBABA_CLOUD).InheritsFrom("qwen3")
|
||||
.Reasoning(ReasoningSupport.ON_BY_DEFAULT);
|
||||
|
||||
builder.Rule("qwen3.7").AsPrefix().AlsoContains("preview").OnlyOn(LLMProviders.ALIBABA_CLOUD).Inherits()
|
||||
.Reasoning(ReasoningSupport.ALWAYS);
|
||||
|
||||
builder.Rule("qwen3.7").AsPrefix().AlsoContains("2026-05-17").OnlyOn(LLMProviders.ALIBABA_CLOUD).Inherits();
|
||||
|
||||
builder.Rule("qwen3.7").AsPrefix().AlsoContains("2026-06-08").OnlyOn(LLMProviders.ALIBABA_CLOUD)
|
||||
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | VIDEO_INPUT | TEXT_OUTPUT | FUNCTION_CALLING)
|
||||
.Apis(CHAT_COMPLETION_API)
|
||||
.Reasoning(ReasoningSupport.ON_BY_DEFAULT);
|
||||
|
||||
// Qwen 3.8, whose 27B checkpoint is what the tier without a size resolves to:
|
||||
builder.Rule("qwen3.8").AsPrefix().OnlyOn(LLMProviders.ALIBABA_CLOUD).InheritsFrom("qwen3")
|
||||
.Capabilities(MULTIPLE_IMAGE_INPUT)
|
||||
.Reasoning(ReasoningSupport.ON_BY_DEFAULT);
|
||||
|
||||
builder.Rule("qwen3.8-flash").AsPrefix().OnlyOn(LLMProviders.ALIBABA_CLOUD).Inherits()
|
||||
.Capabilities(VIDEO_INPUT);
|
||||
|
||||
//
|
||||
// Unlike the open-weight checkpoint of the same name, the Max model keeps its vision when
|
||||
// it is reached through Model Studio:
|
||||
//
|
||||
builder.Rule("qwen3.8-max").AsPrefix().OnlyOn(LLMProviders.ALIBABA_CLOUD).InheritsFrom("qwen3.8-flash")
|
||||
.Reasoning(ReasoningSupport.ALWAYS);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
using static AIStudio.Provider.Capability;
|
||||
|
||||
namespace AIStudio.Models.Alibaba;
|
||||
|
||||
/// <summary>
|
||||
/// The Qwen Omni models, which take everything in and answer in text or in speech.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Alibaba lists the Qwen3 Omni series among the models which call functions and leaves the older
|
||||
/// ones off that list, which is the whole difference between the two rules below.
|
||||
/// </remarks>
|
||||
public sealed class ModelStudioQwenOmniFamily : ModelFamily
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override ModelVendor Vendor => ModelVendor.ALIBABA;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ModelSource Source => new("https://www.alibabacloud.com/help/en/model-studio/models", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Alibaba.cs: every modality in, text and speech out, tool calling from Qwen3 on.");
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Declare(ModelFamilyBuilder builder)
|
||||
{
|
||||
builder.Rule("qwen").AsSubstring().AlsoContains("omni").OnlyOn(LLMProviders.ALIBABA_CLOUD)
|
||||
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | AUDIO_INPUT | SPEECH_INPUT | VIDEO_INPUT | TEXT_OUTPUT | SPEECH_OUTPUT)
|
||||
.Apis(CHAT_COMPLETION_API);
|
||||
|
||||
builder.Rule("qwen3").AsPrefix().AlsoContains("omni").OnlyOn(LLMProviders.ALIBABA_CLOUD).Inherits()
|
||||
.Capabilities(FUNCTION_CALLING);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
using static AIStudio.Provider.Capability;
|
||||
|
||||
namespace AIStudio.Models.Alibaba;
|
||||
|
||||
/// <summary>
|
||||
/// The Qwen VL models, the ones built to look at pictures.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// As with the Omni series, Alibaba names only the Qwen3 VL models as function callers and the
|
||||
/// older ones not at all.
|
||||
/// </remarks>
|
||||
public sealed class ModelStudioQwenVisionFamily : ModelFamily
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override ModelVendor Vendor => ModelVendor.ALIBABA;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ModelSource Source => new("https://www.alibabacloud.com/help/en/model-studio/models", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Alibaba.cs: images in, and tool calling from Qwen3 on.");
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Declare(ModelFamilyBuilder builder)
|
||||
{
|
||||
builder.Rule("qwen").AsSubstring().AlsoContains("vl").OnlyOn(LLMProviders.ALIBABA_CLOUD)
|
||||
.Capabilities(TEXT_INPUT | MULTIPLE_IMAGE_INPUT | TEXT_OUTPUT)
|
||||
.Apis(CHAT_COMPLETION_API);
|
||||
|
||||
builder.Rule("qwen3").AsPrefix().AlsoContains("vl").OnlyOn(LLMProviders.ALIBABA_CLOUD).Inherits()
|
||||
.Capabilities(FUNCTION_CALLING);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
using static AIStudio.Provider.Capability;
|
||||
|
||||
namespace AIStudio.Models.Alibaba;
|
||||
|
||||
/// <summary>
|
||||
/// QwQ as Model Studio serves it, which is qwq-plus.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is the contradiction the provider-bound rules were built for. What Model Studio sells under
|
||||
/// this name is a commercial thinking-only model built on Qwen 2.5; QwQ-32B, which everybody else
|
||||
/// serves, is the open-weight model. They share a family name and nothing else, and the old rules
|
||||
/// could only keep them apart by living in two different functions.
|
||||
///
|
||||
/// Neither of them appears in Alibaba's list of models which call functions, and the model card of
|
||||
/// the open weights does not mention tools at all, which is why no such ability is stated here.
|
||||
/// Anybody who knows better turns it on in the expert settings.
|
||||
/// </remarks>
|
||||
public sealed class ModelStudioQwqFamily : ModelFamily
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override ModelVendor Vendor => ModelVendor.ALIBABA;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ModelSource Source => new("https://www.alibabacloud.com/help/en/model-studio/models", new DateOnly(2026, 9, 11), "Ported unchanged from the rules in ProviderExtensions.Alibaba.cs: text in, text out, thinking which cannot be switched off, and no tools.");
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Declare(ModelFamilyBuilder builder) =>
|
||||
builder.Rule("qwq").AsSegment().OnlyOn(LLMProviders.ALIBABA_CLOUD)
|
||||
.Capabilities(TEXT_INPUT | TEXT_OUTPUT)
|
||||
.Apis(CHAT_COMPLETION_API)
|
||||
.Reasoning(ReasoningSupport.ALWAYS);
|
||||
}
|
||||
@ -38,14 +38,23 @@ public sealed class ModelFamilyBuilder(string origin)
|
||||
{
|
||||
var built = new List<ModelRule>(this.stated.Count);
|
||||
var byPatternText = new Dictionary<string, ModelProfileChange>(StringComparer.Ordinal);
|
||||
var statedMoreThanOnce = new HashSet<string>(StringComparer.Ordinal);
|
||||
ModelProfileChange? previous = null;
|
||||
|
||||
foreach (var statement in this.stated)
|
||||
{
|
||||
var rule = statement.Build(statement.InheritanceBasis(byPatternText, previous));
|
||||
var rule = statement.Build(statement.InheritanceBasis(byPatternText, statedMoreThanOnce, previous));
|
||||
|
||||
built.Add(rule);
|
||||
byPatternText[rule.Pattern.Text] = rule.Change;
|
||||
|
||||
//
|
||||
// The same text may well be stated twice, with different conditions on top -- that is
|
||||
// how a variant of a generation is written. What cannot be done afterwards is naming
|
||||
// that text to inherit from, because it no longer names one rule.
|
||||
//
|
||||
if (!byPatternText.TryAdd(rule.Pattern.Text, rule.Change))
|
||||
statedMoreThanOnce.Add(rule.Pattern.Text);
|
||||
|
||||
previous = rule.Change;
|
||||
}
|
||||
|
||||
|
||||
@ -249,14 +249,25 @@ public sealed class ModelRuleBuilder(string patternText, ModelRuleKind ruleKind,
|
||||
/// What this rule goes on from, if it goes on from anything.
|
||||
/// </summary>
|
||||
/// <param name="byPatternText">What the rules stated so far, by their pattern text.</param>
|
||||
/// <param name="statedMoreThanOnce">The texts which name more than one rule of this family.</param>
|
||||
/// <param name="previous">What the rule stated right before this one, if there was one.</param>
|
||||
/// <returns>The statement to start from, or null when the rule states everything itself.</returns>
|
||||
internal ModelProfileChange? InheritanceBasis(IReadOnlyDictionary<string, ModelProfileChange> byPatternText, ModelProfileChange? previous)
|
||||
internal ModelProfileChange? InheritanceBasis(IReadOnlyDictionary<string, ModelProfileChange> byPatternText, IReadOnlySet<string> statedMoreThanOnce, ModelProfileChange? previous)
|
||||
{
|
||||
if (this.inheritsFromText is not null)
|
||||
{
|
||||
//
|
||||
// A text stated twice names two rules, and taking whichever happened to come last
|
||||
// would be a coin toss nobody sees. The way out is the plain form, which says "the one
|
||||
// before" and means exactly one rule.
|
||||
//
|
||||
if (statedMoreThanOnce.Contains(this.inheritsFromText))
|
||||
throw new InvalidOperationException($"The rule \"{patternText}\" of {origin} inherits from \"{this.inheritsFromText}\", which this family states more than once. Use Inherits() right after the rule to go on from, or give the rule a text of its own.");
|
||||
|
||||
return byPatternText.TryGetValue(this.inheritsFromText, out var named)
|
||||
? named
|
||||
: throw new InvalidOperationException($"The rule \"{patternText}\" of {origin} inherits from \"{this.inheritsFromText}\", which this family does not state before it.");
|
||||
}
|
||||
|
||||
if (!this.inheritsFromPrevious)
|
||||
return null;
|
||||
|
||||
@ -110,6 +110,21 @@ public sealed class ModelFamilyTests
|
||||
Assert.That(refused?.Message, Does.Contain("does not state"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InheritingFromARuleTextWhichNamesTwoRulesSaysSo()
|
||||
{
|
||||
//
|
||||
// Stating one text twice is ordinary: a variant of a generation is written as the same
|
||||
// pattern with a condition on top. What cannot be done afterwards is naming that text to
|
||||
// inherit from, because it no longer names one rule -- and taking whichever came last
|
||||
// would be a coin toss nobody sees.
|
||||
//
|
||||
var family = new FamilyStatingOneTextTwice();
|
||||
var refused = Assert.Throws<InvalidOperationException>(() => _ = family.Rules);
|
||||
|
||||
Assert.That(refused?.Message, Does.Contain("more than once"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AFamilyWhichAdjustsRatherThanChoosesStatesAModifier()
|
||||
{
|
||||
@ -221,6 +236,20 @@ public sealed class ModelFamilyTests
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class FamilyStatingOneTextTwice : ModelFamily
|
||||
{
|
||||
public override ModelVendor Vendor => ModelVendor.UNKNOWN;
|
||||
|
||||
public override ModelSource Source => new("https://example.invalid/twice", new DateOnly(2026, 9, 11), "A family stating one pattern text twice and then naming it to inherit from.");
|
||||
|
||||
protected override void Declare(ModelFamilyBuilder builder)
|
||||
{
|
||||
builder.Rule("thing").Capabilities(Capability.TEXT_INPUT);
|
||||
builder.Rule("thing").AlsoContains("special").Capabilities(Capability.FUNCTION_CALLING);
|
||||
builder.Rule("thing-mini").InheritsFrom("thing");
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class FamilyWithAModifier : ModelFamily
|
||||
{
|
||||
public override ModelVendor Vendor => ModelVendor.UNKNOWN;
|
||||
|
||||
@ -33,6 +33,7 @@ public sealed class PortingDifferenceTests
|
||||
LLMProviders.ANTHROPIC,
|
||||
LLMProviders.GOOGLE,
|
||||
LLMProviders.MISTRAL,
|
||||
LLMProviders.ALIBABA_CLOUD,
|
||||
];
|
||||
|
||||
[Test]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user