mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-06 08:09:40 +00:00
Delete the old capability rules
This commit is contained in:
17 files changed
+308
-2862
No files matched your search
@@ -1,220 +0,0 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public static partial class ProviderExtensions
|
||||
{
|
||||
private static List<Capability> GetModelCapabilitiesAlibaba(Model model)
|
||||
{
|
||||
var modelName = NormalizeModelId(model.Id).AsSpan();
|
||||
|
||||
// Qwen models:
|
||||
if (modelName.StartsWith("qwen"))
|
||||
{
|
||||
// Check for omni models. Alibaba lists the Qwen3 and Qwen3.5 Omni series among the
|
||||
// models which call functions; the older qwen-omni ones are not on that list, which
|
||||
// is what the version check separates here:
|
||||
if (modelName.IndexOf("omni") is not -1)
|
||||
{
|
||||
if (modelName.StartsWith("qwen3"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.AUDIO_INPUT, Capability.SPEECH_INPUT,
|
||||
Capability.VIDEO_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT, Capability.SPEECH_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.AUDIO_INPUT, Capability.SPEECH_INPUT,
|
||||
Capability.VIDEO_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT, Capability.SPEECH_OUTPUT,
|
||||
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
|
||||
// Check for Qwen 3.5:
|
||||
if(modelName.StartsWith("qwen3.5"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Check for Qwen 3.6 family:
|
||||
if(modelName.StartsWith("qwen3.6"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.VIDEO_INPUT,
|
||||
Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Check for the Qwen 3.7 family. Thinking is optional here and switched on by
|
||||
// default, except for the two preview snapshots, which do nothing else:
|
||||
if(modelName.StartsWith("qwen3.7"))
|
||||
{
|
||||
if(modelName.IndexOf("-preview") is not -1 ||
|
||||
modelName.IndexOf("-2026-05-17") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Vision arrived in the middle of the series. The rolling qwen3.7-max alias
|
||||
// still answers as the text-only May snapshot, so only the June one may be
|
||||
// told that it reads images and video:
|
||||
if(modelName.IndexOf("-2026-06-08") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT, Capability.VIDEO_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.REASONING_BY_DEFAULT, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.REASONING_BY_DEFAULT, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
|
||||
// Check for the Qwen 3.8 family:
|
||||
if(modelName.StartsWith("qwen3.8"))
|
||||
{
|
||||
// Flash thinks by default, but thinking can be turned off:
|
||||
if(modelName.StartsWith("qwen3.8-flash"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT, Capability.VIDEO_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.REASONING_BY_DEFAULT, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Unlike the open-weight checkpoint, the Max model keeps its vision
|
||||
// capabilities when used through Alibaba Cloud:
|
||||
if(modelName.StartsWith("qwen3.8-max"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT, Capability.VIDEO_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// All other 3.8 models, such as the 27B one:
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.REASONING_BY_DEFAULT, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
|
||||
// Check for the VL models. Alibaba names the Qwen3-VL Plus and Flash series as
|
||||
// function callers; the older qwen-vl models are absent from that list:
|
||||
if(modelName.IndexOf("-vl-") is not -1)
|
||||
{
|
||||
if(modelName.StartsWith("qwen3"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
|
||||
// Check for Qwen 3:
|
||||
if(modelName.StartsWith("qwen3"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
|
||||
//
|
||||
// QwQ models. What Model Studio serves under this name is qwq-plus, a commercial
|
||||
// thinking-only model built on Qwen2.5. It is not the same model as the open-weight
|
||||
// QwQ-32B, which the rules for open source models cover; the two only share a family
|
||||
// name. 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 this
|
||||
// states no such ability. Anybody who knows better can turn it on in the expert settings.
|
||||
//
|
||||
if (modelName.StartsWith("qwq"))
|
||||
{
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
|
||||
// QVQ models:
|
||||
if (modelName.StartsWith("qvq"))
|
||||
{
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
|
||||
// Default to text input and output:
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public static partial class ProviderExtensions
|
||||
{
|
||||
private static List<Capability> GetModelCapabilitiesAnthropic(Model model)
|
||||
{
|
||||
var modelName = NormalizeModelId(model.Id).AsSpan();
|
||||
|
||||
// Claude Fable 5 and Mythos 5 always use adaptive thinking:
|
||||
if(modelName.StartsWith("claude-fable-5") || modelName.StartsWith("claude-mythos-5"))
|
||||
return [
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Claude Opus 5 and Sonnet 5 think adaptively unless thinking is turned off:
|
||||
if(modelName.StartsWith("claude-opus-5") || modelName.StartsWith("claude-sonnet-5"))
|
||||
return [
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.REASONING_BY_DEFAULT, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Claude Haiku 4.5 needs an explicit thinking budget to reason:
|
||||
if(modelName.StartsWith("claude-haiku-4-5"))
|
||||
return [
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Claude 4.x models:
|
||||
if(modelName.StartsWith("claude-opus-4") || modelName.StartsWith("claude-sonnet-4"))
|
||||
return [
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Claude 3.7 is able to do reasoning:
|
||||
if(modelName.StartsWith("claude-3-7"))
|
||||
return [
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// All other 3.x models are able to process text and images as input:
|
||||
if(modelName.StartsWith("claude-3-"))
|
||||
return [
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Any other model. Every current Claude model accepts images, so we assume the
|
||||
// same for models we do not know yet:
|
||||
return [
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public static partial class ProviderExtensions
|
||||
{
|
||||
private static List<Capability> GetModelCapabilitiesDeepSeek(Model model)
|
||||
{
|
||||
var modelName = NormalizeModelId(model.Id).AsSpan();
|
||||
|
||||
// The reasoner alias points to the thinking mode of the current flash model:
|
||||
if(modelName.IndexOf("reasoner") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// The chat alias points to the non-thinking mode of the same model:
|
||||
if(modelName.IndexOf("chat") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// DeepSeek publishes its models as open weights and offers them under the same
|
||||
// names here. Instead of maintaining a second copy of those rules, we reuse the
|
||||
// ones for open source models:
|
||||
return GetModelCapabilitiesOpenSource(model);
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public static partial class ProviderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines the capabilities of a model offered through a gateway.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A gateway serves the models of many other providers rather than models of its own. OpenRouter,
|
||||
/// LiteLLM, and the Hugging Face router all work that way, and all three name their models the
|
||||
/// same: "vendor/model-name".
|
||||
/// </remarks>
|
||||
/// <param name="model">The model as the gateway names it.</param>
|
||||
/// <returns>The capabilities of the model when reached through a gateway.</returns>
|
||||
private static List<Capability> GetModelCapabilitiesGateway(Model model)
|
||||
{
|
||||
//
|
||||
// Model IDs follow the pattern "vendor/model-name". Examples:
|
||||
// - openai/gpt-5.6
|
||||
// - anthropic/claude-opus-5
|
||||
// - google/gemini-3.7-flash
|
||||
// - qwen/qwen3.8-flash-next
|
||||
//
|
||||
// A gateway offers the models of all the other providers. Instead of keeping a
|
||||
// second set of rules here, which would always lag behind, we hand the model
|
||||
// over to the provider implementation which already knows it. The vendor prefix
|
||||
// has to be removed first: some of those implementations match the beginning of
|
||||
// the model name and would not recognize a prefixed ID.
|
||||
//
|
||||
var separatorIndex = model.Id.IndexOf('/');
|
||||
var vendor = separatorIndex is -1 ? string.Empty : model.Id[..separatorIndex].ToLowerInvariant();
|
||||
var bareModel = separatorIndex is -1 ? model : model with { Id = model.Id[(separatorIndex + 1)..] };
|
||||
var bareModelName = NormalizeModelId(bareModel.Id).AsSpan();
|
||||
|
||||
var capabilities = vendor switch
|
||||
{
|
||||
// The gpt-oss models are open weights. The OpenAI implementation does not
|
||||
// know them, because they are not part of the OpenAI cloud offering:
|
||||
"openai" when bareModelName.IndexOf("gpt-oss") is not -1 => GetModelCapabilitiesOpenSource(bareModel),
|
||||
"openai" => GetModelCapabilitiesOpenAI(bareModel),
|
||||
|
||||
"anthropic" => GetModelCapabilitiesAnthropic(bareModel),
|
||||
|
||||
// Gemma is open weights, Gemini is not:
|
||||
"google" when bareModelName.IndexOf("gemma") is not -1 => GetModelCapabilitiesOpenSource(bareModel),
|
||||
"google" => GetModelCapabilitiesGoogle(bareModel),
|
||||
|
||||
"mistralai" => GetModelCapabilitiesMistral(bareModel),
|
||||
"perplexity" => GetModelCapabilitiesPerplexity(bareModel),
|
||||
|
||||
// Everything else is open source: Qwen, Llama, GLM, Kimi, Muse, Hunyuan,
|
||||
// Nemotron, Grok, and whatever a gateway adds next. DeepSeek belongs here
|
||||
// as well: its own implementation covers the aliases of the DeepSeek
|
||||
// platform, while the gateways use the names of the open weights.
|
||||
_ => GetModelCapabilitiesOpenSource(bareModel),
|
||||
};
|
||||
|
||||
return NormalizeForGateway(capabilities);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adjusts the capabilities reported by another provider for use through a gateway.
|
||||
/// </summary>
|
||||
/// <param name="capabilities">The capabilities as reported by the provider implementation.</param>
|
||||
/// <returns>The capabilities as they apply when using the model through a gateway.</returns>
|
||||
/// <remarks>
|
||||
/// A gateway serves every model through its OpenAI-compatible chat completion API.
|
||||
/// The Responses API is not available there, no matter which API the original
|
||||
/// provider offers.
|
||||
///
|
||||
/// The same holds for a provider which resells a model under its plain name instead of
|
||||
/// prefixing it with the vendor, such as GWDG. Those go through the open source rules, which
|
||||
/// call this for the very same reason.
|
||||
/// </remarks>
|
||||
private static List<Capability> NormalizeForGateway(List<Capability> capabilities)
|
||||
{
|
||||
capabilities.Remove(Capability.RESPONSES_API);
|
||||
if(!capabilities.Contains(Capability.CHAT_COMPLETION_API))
|
||||
capabilities.Add(Capability.CHAT_COMPLETION_API);
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public static partial class ProviderExtensions
|
||||
{
|
||||
private static List<Capability> GetModelCapabilitiesGoogle(Model model)
|
||||
{
|
||||
var modelName = NormalizeModelId(model.Id).AsSpan();
|
||||
|
||||
if (modelName.IndexOf("gemini-") is not -1)
|
||||
{
|
||||
//
|
||||
// Image generation models. They carry a version number like every other model and
|
||||
// have to be asked about first, or gemini-3-pro-image would be read as a chat model
|
||||
// of the 3.x line and be promised function calling. No image model of the family
|
||||
// offers that; what they do offer, and the chat models do not, is writing images.
|
||||
//
|
||||
if (modelName.IndexOf("-image") is not -1)
|
||||
{
|
||||
// Of the image models, only the 3.1 Flash ones read video. They think about
|
||||
// complex prompts, and, as with the 3.x chat models, thinking cannot be
|
||||
// switched off:
|
||||
if (modelName.IndexOf("gemini-3.1-flash") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT, Capability.VIDEO_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT, Capability.IMAGE_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Every other Gemini 3 image model thinks as well, it just does not read video:
|
||||
if (modelName.IndexOf("gemini-3") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT, Capability.IMAGE_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// The older image models, such as the 2.5 Flash one, do not think:
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT, Capability.IMAGE_OUTPUT,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
|
||||
// Chat-compatible Gemini 3.x reasoning models. We match the entire 3.x line
|
||||
// so that new releases are covered as well: they all reason, and the
|
||||
// thinking level can only be lowered, never turned off. That holds for the
|
||||
// Flash Lite models of this line too, which is what sets them apart from
|
||||
// Gemini 2.5 Flash Lite below: there, thinking is off until it is asked for,
|
||||
// while here the lowest level still thinks. The two rolling aliases carry no
|
||||
// version number and are listed separately:
|
||||
if (modelName.IndexOf("gemini-3") is not -1 ||
|
||||
modelName is "gemini-flash-latest" ||
|
||||
modelName is "gemini-pro-latest")
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT, Capability.AUDIO_INPUT,
|
||||
Capability.SPEECH_INPUT, Capability.VIDEO_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Gemini 2.5 Flash Lite supports thinking, but the default is off:
|
||||
if (modelName.IndexOf("gemini-2.5-flash-lite") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT, Capability.AUDIO_INPUT,
|
||||
Capability.SPEECH_INPUT, Capability.VIDEO_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.OPTIONAL_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Reasoning models:
|
||||
if (modelName.IndexOf("gemini-2.5") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT, Capability.AUDIO_INPUT,
|
||||
Capability.SPEECH_INPUT, Capability.VIDEO_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Realtime model:
|
||||
if(modelName.IndexOf("-2.0-flash-live-") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.AUDIO_INPUT, Capability.SPEECH_INPUT,
|
||||
Capability.VIDEO_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT, Capability.SPEECH_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
//
|
||||
// There used to be a branch here which withheld function calling from the 2.0 Flash
|
||||
// models. It said the wrong thing about them, and it only ever caught the dated IDs
|
||||
// because it asked for a trailing hyphen: the plain gemini-2.0-flash alias walked
|
||||
// past it and got a different answer than gemini-2.0-flash-001, which is the same
|
||||
// model. Both questions are moot now, because Google shut the 2.0 Flash chat models
|
||||
// down on 1 June 2026. Anything still asking for one of those names gets the default
|
||||
// below. The live model above keeps its branch: it belongs to a different API whose
|
||||
// retirement Google announces separately.
|
||||
//
|
||||
|
||||
// The old 1.0 pro vision model:
|
||||
if(modelName.IndexOf("pro-vision") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Default to all other Gemini models:
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT, Capability.AUDIO_INPUT,
|
||||
Capability.SPEECH_INPUT, Capability.VIDEO_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
|
||||
// Default for all other models:
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public static partial class ProviderExtensions
|
||||
{
|
||||
//
|
||||
// Mistral names its models after the month they were released: mistral-large-2512 is
|
||||
// Mistral Large 3 from December 2025. The version number lives in the marketing name only,
|
||||
// so matching on it misses nearly every model the API actually serves. The constants below
|
||||
// read as YYMM and say from which release on a family gained a capability.
|
||||
//
|
||||
private const int MISTRAL_LARGE_VISION_SINCE = 2512; // Mistral Large 3
|
||||
private const int MISTRAL_LARGE_REASONING_SINCE = 2512; // Mistral Large 3
|
||||
private const int MISTRAL_MEDIUM_VISION_SINCE = 2505; // Mistral Medium 3
|
||||
private const int MISTRAL_MEDIUM_REASONING_SINCE = 2604; // Mistral Medium 3.5
|
||||
private const int MISTRAL_SMALL_VISION_SINCE = 2503; // Mistral Small 3.1
|
||||
private const int MISTRAL_SMALL_REASONING_SINCE = 2603; // Mistral Small 4
|
||||
private const int MINISTRAL_VISION_SINCE = 2512; // Ministral 3
|
||||
|
||||
/// <summary>
|
||||
/// Used for families which have no reasoning at all. No release date can ever reach it.
|
||||
/// </summary>
|
||||
private const int MISTRAL_REASONING_NEVER = int.MaxValue;
|
||||
|
||||
//
|
||||
// Where the "latest" aliases point to. Mistral moves them on with every release, so they
|
||||
// have to behave like the release they resolve to instead of carrying their own rules.
|
||||
//
|
||||
private const int MISTRAL_LARGE_LATEST = 2512;
|
||||
private const int MISTRAL_MEDIUM_LATEST = 2604;
|
||||
private const int MISTRAL_SMALL_LATEST = 2603;
|
||||
private const int MINISTRAL_LATEST = 2512;
|
||||
|
||||
/// <summary>
|
||||
/// Mistral released its first date-named model in 2023. Anything below that is not a release
|
||||
/// date but a parameter count or a context size which happens to have four digits.
|
||||
/// </summary>
|
||||
private const int MISTRAL_FIRST_RELEASE_YEAR = 23;
|
||||
|
||||
//
|
||||
// Mistral serves some models under their marketing version as well, and it 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 we map them onto the release they stand for. The order
|
||||
// matters: the more specific version has to come first, otherwise "3" would swallow "3.5".
|
||||
//
|
||||
private static readonly (string VersionName, int ReleaseDate)[] MISTRAL_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),
|
||||
];
|
||||
|
||||
private static List<Capability> GetModelCapabilitiesMistral(Model model)
|
||||
{
|
||||
var modelName = NormalizeModelId(model.Id).AsSpan();
|
||||
|
||||
// Pixtral models are able to do process images:
|
||||
if (modelName.IndexOf("pixtral") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
// Mistral saba:
|
||||
if (modelName.IndexOf("mistral-saba-") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
//
|
||||
// The four families Mistral versions by release date. Ministral has to be matched before
|
||||
// the others, although its name does not contain "mistral" as a substring: keeping the
|
||||
// families together makes the block easier to read.
|
||||
//
|
||||
if (modelName.IndexOf("ministral") is not -1)
|
||||
return BuildMistralCapabilities(GetMistralReleaseDate(modelName, MINISTRAL_LATEST), MINISTRAL_VISION_SINCE, MISTRAL_REASONING_NEVER);
|
||||
|
||||
if (modelName.IndexOf("mistral-large") is not -1)
|
||||
return BuildMistralCapabilities(GetMistralReleaseDate(modelName, MISTRAL_LARGE_LATEST), MISTRAL_LARGE_VISION_SINCE, MISTRAL_LARGE_REASONING_SINCE);
|
||||
|
||||
if (modelName.IndexOf("mistral-medium") is not -1)
|
||||
return BuildMistralCapabilities(GetMistralReleaseDate(modelName, MISTRAL_MEDIUM_LATEST), MISTRAL_MEDIUM_VISION_SINCE, MISTRAL_MEDIUM_REASONING_SINCE);
|
||||
|
||||
if (modelName.IndexOf("mistral-small") is not -1)
|
||||
return BuildMistralCapabilities(GetMistralReleaseDate(modelName, MISTRAL_SMALL_LATEST), MISTRAL_SMALL_VISION_SINCE, MISTRAL_SMALL_REASONING_SINCE);
|
||||
|
||||
// Default:
|
||||
return GetModelCapabilitiesOpenSource(model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines the release date a Mistral model belongs to.
|
||||
/// </summary>
|
||||
/// <param name="modelName">The lowercase model name to inspect.</param>
|
||||
/// <param name="latestReleaseDate">The release the family's "latest" alias points to.</param>
|
||||
/// <returns>The release date as YYMM, or 0 when the name carries none.</returns>
|
||||
private static int GetMistralReleaseDate(ReadOnlySpan<char> modelName, int latestReleaseDate)
|
||||
{
|
||||
// The "latest" alias always points to the newest release of its family:
|
||||
if (modelName.IndexOf("-latest") is not -1)
|
||||
return latestReleaseDate;
|
||||
|
||||
foreach (var (versionName, releaseDate) in MISTRAL_VERSION_NAMES)
|
||||
if (modelName.IndexOf(versionName) is not -1)
|
||||
return releaseDate;
|
||||
|
||||
return ReadMistralReleaseDate(modelName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the four-digit release date out of a Mistral model 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
|
||||
/// must resolve to 2512 and not to anything the "14b" part could be read as.
|
||||
/// </remarks>
|
||||
/// <param name="modelName">The lowercase model name to inspect.</param>
|
||||
/// <returns>The release date as YYMM, or 0 when the name carries none.</returns>
|
||||
private static int ReadMistralReleaseDate(ReadOnlySpan<char> modelName)
|
||||
{
|
||||
for (var index = 0; index + 4 <= 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 + 4 < modelName.Length && char.IsAsciiDigit(modelName[index + 4]))
|
||||
continue;
|
||||
|
||||
var candidate = modelName.Slice(index, 4);
|
||||
if (!char.IsAsciiDigit(candidate[0]) || !char.IsAsciiDigit(candidate[1]) ||
|
||||
!char.IsAsciiDigit(candidate[2]) || !char.IsAsciiDigit(candidate[3]))
|
||||
continue;
|
||||
|
||||
var releaseDate = int.Parse(candidate);
|
||||
var year = releaseDate / 100;
|
||||
var month = releaseDate % 100;
|
||||
if (year < MISTRAL_FIRST_RELEASE_YEAR || month is < 1 or > 12)
|
||||
continue;
|
||||
|
||||
return releaseDate;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the capabilities of a Mistral model from its release date.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A model whose release date we cannot read gets neither image input nor reasoning. That is
|
||||
/// the safe direction: offering an ability the model does not have would fail the request,
|
||||
/// whereas a missing one can be added by hand through the capability overrides.
|
||||
/// </remarks>
|
||||
/// <param name="releaseDate">The release date of the model as YYMM, or 0 when unknown.</param>
|
||||
/// <param name="visionSince">The release from which this family accepts images.</param>
|
||||
/// <param name="reasoningSince">The release from which this family can reason.</param>
|
||||
/// <returns>The capabilities of the model.</returns>
|
||||
private static List<Capability> BuildMistralCapabilities(int releaseDate, int visionSince, int reasoningSince)
|
||||
{
|
||||
List<Capability> capabilities = [Capability.TEXT_INPUT, Capability.FUNCTION_CALLING, Capability.CHAT_COMPLETION_API, Capability.TEXT_OUTPUT];
|
||||
|
||||
if (releaseDate >= visionSince)
|
||||
capabilities.Add(Capability.MULTIPLE_IMAGE_INPUT);
|
||||
|
||||
if (releaseDate >= reasoningSince)
|
||||
capabilities.Add(Capability.OPTIONAL_REASONING);
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
}
|
||||
@@ -1,226 +0,0 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public static partial class ProviderExtensions
|
||||
{
|
||||
private static List<Capability> GetModelCapabilitiesOpenAI(Model model)
|
||||
{
|
||||
var modelName = NormalizeModelId(model.Id).AsSpan();
|
||||
|
||||
if (modelName is "gpt-4o-search-preview")
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
if (modelName is "gpt-4o-mini-search-preview")
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
if (modelName.StartsWith("o1-mini"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
if(modelName is "gpt-3.5-turbo")
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
Capability.RESPONSES_API,
|
||||
];
|
||||
|
||||
if(modelName.StartsWith("gpt-3.5"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
if (modelName.StartsWith("o3-mini"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.RESPONSES_API,
|
||||
];
|
||||
|
||||
if (modelName.StartsWith("o4-mini") || modelName.StartsWith("o3"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.RESPONSES_API,
|
||||
];
|
||||
|
||||
if (modelName.StartsWith("o1"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING, Capability.FUNCTION_CALLING,
|
||||
Capability.RESPONSES_API,
|
||||
];
|
||||
|
||||
if(modelName.StartsWith("gpt-4-turbo"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.RESPONSES_API,
|
||||
];
|
||||
|
||||
if(modelName is "gpt-4" || modelName.StartsWith("gpt-4-"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
Capability.RESPONSES_API,
|
||||
];
|
||||
|
||||
if(modelName.StartsWith("gpt-5-nano"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING, Capability.ALWAYS_REASONING,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.RESPONSES_API,
|
||||
];
|
||||
|
||||
if(modelName is "gpt-5" || modelName.StartsWith("gpt-5-"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING, Capability.ALWAYS_REASONING,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.RESPONSES_API,
|
||||
];
|
||||
|
||||
//
|
||||
// None of the GPT-5 models writes images itself. They can ask for one through the
|
||||
// image generation tool, which is a tool call like any other and produces a picture
|
||||
// from a separate model. That is a different thing from an output modality, and we
|
||||
// must not report it as one: the chat would then offer to receive images which never
|
||||
// arrive.
|
||||
//
|
||||
if(modelName is "gpt-5.1" || modelName.StartsWith("gpt-5.1-"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING, Capability.OPTIONAL_REASONING,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.RESPONSES_API, Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
if(modelName is "gpt-5.2" || modelName.StartsWith("gpt-5.2-"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING, Capability.OPTIONAL_REASONING,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.RESPONSES_API, Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
if(modelName is "gpt-5.3" || modelName.StartsWith("gpt-5.3-"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING, Capability.OPTIONAL_REASONING,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.RESPONSES_API, Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
if(modelName is "gpt-5.4" || modelName.StartsWith("gpt-5.4-"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING, Capability.OPTIONAL_REASONING,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.RESPONSES_API, Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
if(modelName is "gpt-5.5" || modelName.StartsWith("gpt-5.5-"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING, Capability.REASONING_BY_DEFAULT,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.RESPONSES_API, Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
if(modelName is "gpt-5.6" || modelName.StartsWith("gpt-5.6-"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING, Capability.REASONING_BY_DEFAULT,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.RESPONSES_API, Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
//
|
||||
// GPT-6 Astra. Unlike the 5.5 and 5.6 models, it reasons on every request: the effort
|
||||
// reaches from low to max, and there is no setting which switches thinking off.
|
||||
//
|
||||
if(modelName is "gpt-6-astra" || modelName.StartsWith("gpt-6-astra-"))
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING, Capability.ALWAYS_REASONING,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.RESPONSES_API, Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT, Capability.MULTIPLE_IMAGE_INPUT,
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.FUNCTION_CALLING,
|
||||
Capability.RESPONSES_API,
|
||||
Capability.WEB_SEARCH,
|
||||
];
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,41 +0,0 @@
|
||||
using AIStudio.Provider;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public static partial class ProviderExtensions
|
||||
{
|
||||
private static List<Capability> GetModelCapabilitiesPerplexity(Model model)
|
||||
{
|
||||
var modelName = NormalizeModelId(model.Id).AsSpan();
|
||||
|
||||
//
|
||||
// No Sonar model writes images. What looked like it does is the option to have the
|
||||
// answer come with images: those are pictures the search found on the pages it read,
|
||||
// handed back as links, not something the model drew.
|
||||
//
|
||||
if(modelName.IndexOf("reasoning") is not -1 ||
|
||||
modelName.IndexOf("deep-research") is not -1)
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.MULTIPLE_IMAGE_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.ALWAYS_REASONING,
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
|
||||
return
|
||||
[
|
||||
Capability.TEXT_INPUT,
|
||||
Capability.MULTIPLE_IMAGE_INPUT,
|
||||
|
||||
Capability.TEXT_OUTPUT,
|
||||
|
||||
Capability.WEB_SEARCH,
|
||||
Capability.CHAT_COMPLETION_API,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,76 +1,11 @@
|
||||
using AIStudio.Models;
|
||||
using AIStudio.Models;
|
||||
using AIStudio.Models.Registry;
|
||||
using AIStudio.Provider;
|
||||
using AIStudio.Provider.HuggingFace;
|
||||
|
||||
namespace AIStudio.Settings;
|
||||
|
||||
public static partial class ProviderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// The longest model ID we normalize without going to the heap.
|
||||
/// </summary>
|
||||
private const int MAX_STACK_ALLOCATED_MODEL_ID_LENGTH = 256;
|
||||
|
||||
/// <summary>
|
||||
/// Brings a model ID into the form the capability rules are written in.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Every provider names the same model differently, and the difference is rarely in the words:
|
||||
/// it is in what sits between them. Ollama separates the variant with a colon
|
||||
/// ("qwen3.8:27b-mlx"), Blablador answers with a whole sentence ("10 - Muse Glimmer 30b - the
|
||||
/// newest META model"), Fireworks puts a path in front
|
||||
/// ("accounts/fireworks/models/llama-v3p1-405b-instruct"), and the hubs use hyphens. Without
|
||||
/// this, every rule would have to spell out each of those writings, which is what the Llama
|
||||
/// block used to do with four variants of one check.
|
||||
///
|
||||
/// The dots stay. They carry the version boundary: llama3 and llama3.1 are different models,
|
||||
/// and only the latter calls functions. Dropping them would merge the two.
|
||||
///
|
||||
/// The patterns in the rules are written in this normalized form already, which is why they
|
||||
/// use lowercase and hyphens throughout.
|
||||
/// </remarks>
|
||||
/// <param name="modelId">The model ID as the provider reports it.</param>
|
||||
/// <returns>The model ID in lowercase, with every separator written as a single hyphen.</returns>
|
||||
private static string NormalizeModelId(string modelId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(modelId))
|
||||
return string.Empty;
|
||||
|
||||
//
|
||||
// Normalizing never makes a name longer, so the original length is always enough room.
|
||||
// Model IDs are short, which is why the buffer lives on the stack: the longest ones we
|
||||
// know of are the descriptive names Blablador answers with, at around 75 characters. A
|
||||
// provider reporting something longer still gets a correct answer, just from the heap.
|
||||
//
|
||||
Span<char> normalized = modelId.Length <= MAX_STACK_ALLOCATED_MODEL_ID_LENGTH
|
||||
? stackalloc char[modelId.Length]
|
||||
: new char[modelId.Length];
|
||||
|
||||
var length = 0;
|
||||
foreach (var character in modelId)
|
||||
{
|
||||
if (char.IsAsciiLetterOrDigit(character) || character is '.')
|
||||
{
|
||||
normalized[length++] = char.ToLowerInvariant(character);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Anything else separates two parts of the name. A leading separator, and a repeated
|
||||
// one, say nothing and would only get in the way of the patterns:
|
||||
if (length is 0 || normalized[length - 1] is '-')
|
||||
continue;
|
||||
|
||||
normalized[length++] = '-';
|
||||
}
|
||||
|
||||
// A trailing separator carries no meaning either:
|
||||
if (length > 0 && normalized[length - 1] is '-')
|
||||
length--;
|
||||
|
||||
return new string(normalized[..length]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Everything the app knows about the model this provider instance is configured with.
|
||||
/// </summary>
|
||||
@@ -118,17 +53,6 @@ public static partial class ProviderExtensions
|
||||
: stated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the capabilities of the model used by the configured provider.
|
||||
/// </summary>
|
||||
/// <param name="provider">The configured provider.</param>
|
||||
/// <returns>The capabilities of the configured model.</returns>
|
||||
public static List<Capability> GetModelCapabilities(this Provider provider)
|
||||
{
|
||||
var automaticCapabilities = provider.UsedLLMProvider.GetModelCapabilities(provider.Model);
|
||||
return provider.CapabilityOverrides?.ApplyTo(automaticCapabilities) ?? automaticCapabilities;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get whether the model used by the configured provider accepts images as input.
|
||||
/// </summary>
|
||||
@@ -141,56 +65,4 @@ public static partial class ProviderExtensions
|
||||
/// <param name="provider">The configured provider.</param>
|
||||
/// <returns><c>true</c> when the model accepts image input.</returns>
|
||||
public static bool SupportsImageInput(this Provider provider) => provider.GetModelProfile().HasAny(Capability.SINGLE_IMAGE_INPUT | Capability.MULTIPLE_IMAGE_INPUT);
|
||||
|
||||
/// <summary>
|
||||
/// Get the capabilities of a model for a specific provider.
|
||||
/// </summary>
|
||||
/// <param name="provider">The LLM provider.</param>
|
||||
/// <param name="model">The model to get the capabilities for.</param>
|
||||
/// <returns>>The capabilities of the model.</returns>
|
||||
public static List<Capability> GetModelCapabilities(this LLMProviders provider, Model model)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(model.Id))
|
||||
return [];
|
||||
|
||||
return provider switch
|
||||
{
|
||||
LLMProviders.OPEN_AI => GetModelCapabilitiesOpenAI(model),
|
||||
LLMProviders.MISTRAL => GetModelCapabilitiesMistral(model),
|
||||
LLMProviders.ANTHROPIC => GetModelCapabilitiesAnthropic(model),
|
||||
LLMProviders.GOOGLE => GetModelCapabilitiesGoogle(model),
|
||||
LLMProviders.X => GetModelCapabilitiesOpenSource(model),
|
||||
LLMProviders.DEEP_SEEK => GetModelCapabilitiesDeepSeek(model),
|
||||
LLMProviders.ALIBABA_CLOUD => GetModelCapabilitiesAlibaba(model),
|
||||
LLMProviders.PERPLEXITY => GetModelCapabilitiesPerplexity(model),
|
||||
LLMProviders.OPEN_ROUTER => GetModelCapabilitiesGateway(model),
|
||||
LLMProviders.HETZNER or LLMProviders.IONOS => GetModelCapabilitiesOpenSource(model),
|
||||
|
||||
//
|
||||
// LiteLLM is a gateway just like OpenRouter, and it names its models the same way:
|
||||
// "vendor/model", e.g. "anthropic/claude-opus-5" or "azure/gpt-5.6". So we let the
|
||||
// gateway detection handle it, which resolves the vendor prefix and asks the
|
||||
// provider who really knows the model. Everything it cannot place is treated as
|
||||
// an open source model, which is the right fallback for a freely named alias:
|
||||
//
|
||||
LLMProviders.LITE_LLM => GetModelCapabilitiesGateway(model),
|
||||
|
||||
LLMProviders.GROQ or LLMProviders.FIREWORKS => GetModelCapabilitiesOpenSource(model),
|
||||
|
||||
//
|
||||
// Hugging Face names its models the way the hub does, "org/model", which is the same
|
||||
// shape the other gateways use. So we let the gateway detection resolve the organization
|
||||
// and ask the provider implementation which really knows the model. The routing suffix
|
||||
// has to go first: it says which inference provider answers, not what the model is.
|
||||
//
|
||||
LLMProviders.HUGGINGFACE => GetModelCapabilitiesGateway(model.WithoutRoutingSuffix()),
|
||||
|
||||
LLMProviders.HELMHOLTZ => GetModelCapabilitiesOpenSource(model),
|
||||
LLMProviders.GWDG => GetModelCapabilitiesOpenSource(model),
|
||||
|
||||
LLMProviders.SELF_HOSTED => GetModelCapabilitiesOpenSource(model),
|
||||
|
||||
_ => []
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user