Turned getter-like extension methods into extension properties (#1157)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-04 13:00:56 +01:00
1 parent 0375318b1b
commit f649febf88
286 files changed
+1379 -1109

No files matched your search

@@ -5,7 +5,7 @@ public static class HostExtensions
/// <param name="host">The engine.</param>
extension(Host host)
{
public string Name() => host switch
public string Name => host switch
{
Host.NONE => "None",
@@ -19,22 +19,22 @@ public static class HostExtensions
_ => "Unknown",
};
public string BaseURL() => host switch
public string BaseURL => host switch
{
_ => "/v1/",
};
public string ChatURL() => host switch
public string ChatURL => host switch
{
_ => "chat/completions",
};
public string TranscriptionURL() => host switch
public string TranscriptionURL => host switch
{
_ => "audio/transcriptions",
};
public string EmbeddingURL() => host switch
public string EmbeddingURL => host switch
{
_ => "embeddings",
};
@@ -43,12 +43,12 @@ public static class HostExtensions
/// The largest image file, in bytes, which the engine accepts in a chat request, where we know of one.
/// </summary>
/// <remarks>
/// Like the limit of a cloud provider, see LLMProvidersExtensions.GetMaxImageSizeBytes, this
/// Like the limit of a cloud provider, see LLMProvidersExtensions.MaxImageSizeBytes, this
/// belongs to the API of the engine, not to the model. What we actually send is asked through
/// IImageSourceExtensions.MaxImageSizeBytesFor.
/// </remarks>
/// <returns>The size limit of one image file, or null when the engine states none we know of.</returns>
public long? GetMaxImageSizeBytes() => host switch
/// <value>The size limit of one image file, or null when the engine states none we know of.</value>
public long? MaxImageSizeBytes => host switch
{
//
// llmman answers a chat request larger than 2 MiB with 413: its route /v1/chat/completions
@@ -61,53 +61,62 @@ public static class HostExtensions
_ => null,
};
public bool IsChatSupported()
public bool IsChatSupported
{
switch (host)
get
{
case Host.WHISPER_CPP:
return false;
default:
case Host.OLLAMA:
case Host.VLLM:
case Host.LM_STUDIO:
case Host.LLAMA_CPP:
case Host.LLMMAN:
return true;
switch (host)
{
case Host.WHISPER_CPP:
return false;
default:
case Host.OLLAMA:
case Host.VLLM:
case Host.LM_STUDIO:
case Host.LLAMA_CPP:
case Host.LLMMAN:
return true;
}
}
}
public bool IsEmbeddingSupported()
public bool IsEmbeddingSupported
{
switch (host)
get
{
case Host.LM_STUDIO:
case Host.OLLAMA:
case Host.VLLM:
case Host.LLMMAN:
return true;
default:
case Host.LLAMA_CPP:
return false;
switch (host)
{
case Host.LM_STUDIO:
case Host.OLLAMA:
case Host.VLLM:
case Host.LLMMAN:
return true;
default:
case Host.LLAMA_CPP:
return false;
}
}
}
public bool IsTranscriptionSupported()
public bool IsTranscriptionSupported
{
switch (host)
get
{
case Host.OLLAMA:
case Host.VLLM:
case Host.WHISPER_CPP:
case Host.LLMMAN:
return true;
switch (host)
{
case Host.OLLAMA:
case Host.VLLM:
case Host.WHISPER_CPP:
case Host.LLMMAN:
return true;
default:
case Host.LM_STUDIO:
case Host.LLAMA_CPP:
return false;
default:
case Host.LM_STUDIO:
case Host.LLAMA_CPP:
return false;
}
}
}
@@ -122,22 +131,25 @@ public static class HostExtensions
/// provider offers that model under a fixed name instead. llama.cpp is, even though builds
/// older than the route answer it with 404; the provider handles those builds itself.
/// </remarks>
/// <returns>True when the models can be loaded from the engine; otherwise, false.</returns>
public bool IsModelListSupported()
/// <value>True when the models can be loaded from the engine; otherwise, false.</value>
public bool IsModelListSupported
{
switch (host)
get
{
case Host.LLAMA_CPP:
case Host.OLLAMA:
case Host.LM_STUDIO:
case Host.VLLM:
case Host.LLMMAN:
return true;
switch (host)
{
case Host.LLAMA_CPP:
case Host.OLLAMA:
case Host.LM_STUDIO:
case Host.VLLM:
case Host.LLMMAN:
return true;
default:
case Host.NONE:
case Host.WHISPER_CPP:
return false;
default:
case Host.NONE:
case Host.WHISPER_CPP:
return false;
}
}
}
}
@@ -10,7 +10,7 @@ using AIStudio.Tools.PluginSystem;
namespace AIStudio.Provider.SelfHosted;
public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvider(LLMProviders.SELF_HOSTED, new Uri($"{hostname}{host.BaseURL()}"), ExternalHttpTrustPolicy.ALLOW_CUSTOM_ROOTS_WHEN_HOST_WHITELISTED, LOGGER)
public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvider(LLMProviders.SELF_HOSTED, new Uri($"{hostname}{host.BaseURL}"), ExternalHttpTrustPolicy.ALLOW_CUSTOM_ROOTS_WHEN_HOST_WHITELISTED, LOGGER)
{
private static readonly ILogger<ProviderSelfHosted> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderSelfHosted>();
@@ -19,13 +19,13 @@ public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvide
#region Implementation of IProvider
/// <inheritdoc />
public override string Id => LLMProviders.SELF_HOSTED.ToSecretId();
public override string Id => LLMProviders.SELF_HOSTED.SecretId;
/// <inheritdoc />
public override string InstanceName { get; set; } = "Self-hosted";
/// <inheritdoc />
public override bool HasModelLoadingCapability => host.IsModelListSupported();
public override bool HasModelLoadingCapability => host.IsModelListSupported;
/// <inheritdoc />
public override async IAsyncEnumerable<ContentStreamChunk> StreamChatCompletion(Provider.Model chatModel, ChatThread chatThread, SettingsManager settingsManager, [EnumeratorCancellation] CancellationToken token = default)
@@ -63,7 +63,7 @@ public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvide
};
},
isTryingSecret: true,
requestPath: host.ChatURL(),
requestPath: host.ChatURL,
token: token))
yield return content;
}
@@ -97,7 +97,7 @@ public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvide
if (host is Host.LLAMA_CPP)
return await this.LoadLlamaCppTextModels(apiKeyProvisional, token);
if (!host.IsChatSupported() || !host.IsModelListSupported())
if (!host.IsChatSupported || !host.IsModelListSupported)
return ModelLoadResult.FromModels([]);
var result = await this.LoadModels(SecretStoreType.LLM_PROVIDER, apiKeyProvisional, token);
@@ -123,7 +123,7 @@ public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvide
{
try
{
if (!host.IsEmbeddingSupported() || !host.IsModelListSupported())
if (!host.IsEmbeddingSupported || !host.IsModelListSupported)
return ModelLoadResult.FromModels([]);
var result = await this.LoadModels(SecretStoreType.EMBEDDING_PROVIDER, apiKeyProvisional, token);
@@ -150,7 +150,7 @@ public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvide
new Provider.Model("loaded-model", TB("Model as configured by whisper.cpp")),
]);
if (!host.IsTranscriptionSupported() || !host.IsModelListSupported())
if (!host.IsTranscriptionSupported || !host.IsModelListSupported)
return ModelLoadResult.FromModels([]);
//