mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-15 20:21:36 +00:00
Refactored provider constructors to include provider enum for improved clarity
This commit is contained in:
parent
b907c3990f
commit
6cac072ffd
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.AlibabaCloud;
|
namespace AIStudio.Provider.AlibabaCloud;
|
||||||
|
|
||||||
public sealed class ProviderAlibabaCloud() : BaseProvider("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/", LOGGER)
|
public sealed class ProviderAlibabaCloud() : BaseProvider(LLMProviders.ALIBABA_CLOUD, "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderAlibabaCloud> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderAlibabaCloud>();
|
private static readonly ILogger<ProviderAlibabaCloud> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderAlibabaCloud>();
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.Anthropic;
|
namespace AIStudio.Provider.Anthropic;
|
||||||
|
|
||||||
public sealed class ProviderAnthropic() : BaseProvider("https://api.anthropic.com/v1/", LOGGER)
|
public sealed class ProviderAnthropic() : BaseProvider(LLMProviders.ANTHROPIC, "https://api.anthropic.com/v1/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderAnthropic> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderAnthropic>();
|
private static readonly ILogger<ProviderAnthropic> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderAnthropic>();
|
||||||
|
|
||||||
|
|||||||
@ -47,11 +47,13 @@ public abstract class BaseProvider : IProvider, ISecretId
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor for the base provider.
|
/// Constructor for the base provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="provider">The provider enum value.</param>
|
||||||
/// <param name="url">The base URL for the provider.</param>
|
/// <param name="url">The base URL for the provider.</param>
|
||||||
/// <param name="logger">The logger to use.</param>
|
/// <param name="logger">The logger to use.</param>
|
||||||
protected BaseProvider(string url, ILogger logger)
|
protected BaseProvider(LLMProviders provider, string url, ILogger logger)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.Provider = provider;
|
||||||
|
|
||||||
// Set the base URL:
|
// Set the base URL:
|
||||||
this.httpClient.BaseAddress = new(url);
|
this.httpClient.BaseAddress = new(url);
|
||||||
@ -59,6 +61,9 @@ public abstract class BaseProvider : IProvider, ISecretId
|
|||||||
|
|
||||||
#region Handling of IProvider, which all providers must implement
|
#region Handling of IProvider, which all providers must implement
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public LLMProviders Provider { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public abstract string Id { get; }
|
public abstract string Id { get; }
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.DeepSeek;
|
namespace AIStudio.Provider.DeepSeek;
|
||||||
|
|
||||||
public sealed class ProviderDeepSeek() : BaseProvider("https://api.deepseek.com/", LOGGER)
|
public sealed class ProviderDeepSeek() : BaseProvider(LLMProviders.DEEP_SEEK, "https://api.deepseek.com/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderDeepSeek> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderDeepSeek>();
|
private static readonly ILogger<ProviderDeepSeek> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderDeepSeek>();
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.Fireworks;
|
namespace AIStudio.Provider.Fireworks;
|
||||||
|
|
||||||
public class ProviderFireworks() : BaseProvider("https://api.fireworks.ai/inference/v1/", LOGGER)
|
public class ProviderFireworks() : BaseProvider(LLMProviders.FIREWORKS, "https://api.fireworks.ai/inference/v1/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderFireworks> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderFireworks>();
|
private static readonly ILogger<ProviderFireworks> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderFireworks>();
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.GWDG;
|
namespace AIStudio.Provider.GWDG;
|
||||||
|
|
||||||
public sealed class ProviderGWDG() : BaseProvider("https://chat-ai.academiccloud.de/v1/", LOGGER)
|
public sealed class ProviderGWDG() : BaseProvider(LLMProviders.GWDG, "https://chat-ai.academiccloud.de/v1/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderGWDG> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderGWDG>();
|
private static readonly ILogger<ProviderGWDG> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderGWDG>();
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.Google;
|
namespace AIStudio.Provider.Google;
|
||||||
|
|
||||||
public class ProviderGoogle() : BaseProvider("https://generativelanguage.googleapis.com/v1beta/", LOGGER)
|
public class ProviderGoogle() : BaseProvider(LLMProviders.GOOGLE, "https://generativelanguage.googleapis.com/v1beta/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderGoogle> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderGoogle>();
|
private static readonly ILogger<ProviderGoogle> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderGoogle>();
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.Groq;
|
namespace AIStudio.Provider.Groq;
|
||||||
|
|
||||||
public class ProviderGroq() : BaseProvider("https://api.groq.com/openai/v1/", LOGGER)
|
public class ProviderGroq() : BaseProvider(LLMProviders.GROQ, "https://api.groq.com/openai/v1/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderGroq> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderGroq>();
|
private static readonly ILogger<ProviderGroq> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderGroq>();
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.Helmholtz;
|
namespace AIStudio.Provider.Helmholtz;
|
||||||
|
|
||||||
public sealed class ProviderHelmholtz() : BaseProvider("https://api.helmholtz-blablador.fz-juelich.de/v1/", LOGGER)
|
public sealed class ProviderHelmholtz() : BaseProvider(LLMProviders.HELMHOLTZ, "https://api.helmholtz-blablador.fz-juelich.de/v1/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderHelmholtz> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderHelmholtz>();
|
private static readonly ILogger<ProviderHelmholtz> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderHelmholtz>();
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ public sealed class ProviderHuggingFace : BaseProvider
|
|||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderHuggingFace> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderHuggingFace>();
|
private static readonly ILogger<ProviderHuggingFace> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderHuggingFace>();
|
||||||
|
|
||||||
public ProviderHuggingFace(HFInferenceProvider hfProvider, Model model) : base($"https://router.huggingface.co/{hfProvider.Endpoints(model)}", LOGGER)
|
public ProviderHuggingFace(HFInferenceProvider hfProvider, Model model) : base(LLMProviders.HUGGINGFACE, $"https://router.huggingface.co/{hfProvider.Endpoints(model)}", LOGGER)
|
||||||
{
|
{
|
||||||
LOGGER.LogInformation($"We use the inferende provider '{hfProvider}'. Thus we use the base URL 'https://router.huggingface.co/{hfProvider.Endpoints(model)}'.");
|
LOGGER.LogInformation($"We use the inferende provider '{hfProvider}'. Thus we use the base URL 'https://router.huggingface.co/{hfProvider.Endpoints(model)}'.");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,11 @@ namespace AIStudio.Provider;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IProvider
|
public interface IProvider
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The provider type.
|
||||||
|
/// </summary>
|
||||||
|
public LLMProviders Provider { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The provider's ID.
|
/// The provider's ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.Mistral;
|
namespace AIStudio.Provider.Mistral;
|
||||||
|
|
||||||
public sealed class ProviderMistral() : BaseProvider("https://api.mistral.ai/v1/", LOGGER)
|
public sealed class ProviderMistral() : BaseProvider(LLMProviders.MISTRAL, "https://api.mistral.ai/v1/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderMistral> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderMistral>();
|
private static readonly ILogger<ProviderMistral> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderMistral>();
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,8 @@ public class NoProvider : IProvider
|
|||||||
{
|
{
|
||||||
#region Implementation of IProvider
|
#region Implementation of IProvider
|
||||||
|
|
||||||
|
public LLMProviders Provider => LLMProviders.NONE;
|
||||||
|
|
||||||
public string Id => "none";
|
public string Id => "none";
|
||||||
|
|
||||||
public string InstanceName { get; set; } = "None";
|
public string InstanceName { get; set; } = "None";
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace AIStudio.Provider.OpenAI;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The OpenAI provider.
|
/// The OpenAI provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class ProviderOpenAI() : BaseProvider("https://api.openai.com/v1/", LOGGER)
|
public sealed class ProviderOpenAI() : BaseProvider(LLMProviders.OPEN_AI, "https://api.openai.com/v1/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderOpenAI> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderOpenAI>();
|
private static readonly ILogger<ProviderOpenAI> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderOpenAI>();
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ public sealed class ProviderOpenAI() : BaseProvider("https://api.openai.com/v1/"
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Read the model capabilities:
|
// Read the model capabilities:
|
||||||
var modelCapabilities = ProviderExtensions.GetModelCapabilitiesOpenAI(chatModel);
|
var modelCapabilities = this.Provider.GetModelCapabilities(chatModel);
|
||||||
|
|
||||||
// Check if we are using the Responses API or the Chat Completion API:
|
// Check if we are using the Responses API or the Chat Completion API:
|
||||||
var usingResponsesAPI = modelCapabilities.Contains(Capability.RESPONSES_API);
|
var usingResponsesAPI = modelCapabilities.Contains(Capability.RESPONSES_API);
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.OpenRouter;
|
namespace AIStudio.Provider.OpenRouter;
|
||||||
|
|
||||||
public sealed class ProviderOpenRouter() : BaseProvider("https://openrouter.ai/api/v1/", LOGGER)
|
public sealed class ProviderOpenRouter() : BaseProvider(LLMProviders.OPEN_ROUTER, "https://openrouter.ai/api/v1/", LOGGER)
|
||||||
{
|
{
|
||||||
private const string PROJECT_WEBSITE = "https://github.com/MindWorkAI/AI-Studio";
|
private const string PROJECT_WEBSITE = "https://github.com/MindWorkAI/AI-Studio";
|
||||||
private const string PROJECT_NAME = "MindWork AI Studio";
|
private const string PROJECT_NAME = "MindWork AI Studio";
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.Perplexity;
|
namespace AIStudio.Provider.Perplexity;
|
||||||
|
|
||||||
public sealed class ProviderPerplexity() : BaseProvider("https://api.perplexity.ai/", LOGGER)
|
public sealed class ProviderPerplexity() : BaseProvider(LLMProviders.PERPLEXITY, "https://api.perplexity.ai/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderPerplexity> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderPerplexity>();
|
private static readonly ILogger<ProviderPerplexity> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderPerplexity>();
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.SelfHosted;
|
namespace AIStudio.Provider.SelfHosted;
|
||||||
|
|
||||||
public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvider($"{hostname}{host.BaseURL()}", LOGGER)
|
public sealed class ProviderSelfHosted(Host host, string hostname) : BaseProvider(LLMProviders.SELF_HOSTED, $"{hostname}{host.BaseURL()}", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderSelfHosted> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderSelfHosted>();
|
private static readonly ILogger<ProviderSelfHosted> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderSelfHosted>();
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using AIStudio.Settings;
|
|||||||
|
|
||||||
namespace AIStudio.Provider.X;
|
namespace AIStudio.Provider.X;
|
||||||
|
|
||||||
public sealed class ProviderX() : BaseProvider("https://api.x.ai/v1/", LOGGER)
|
public sealed class ProviderX() : BaseProvider(LLMProviders.X, "https://api.x.ai/v1/", LOGGER)
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ProviderX> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderX>();
|
private static readonly ILogger<ProviderX> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderX>();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user