AI-Studio/app/MindWork AI Studio/Provider/Providers.cs

62 lines
1.9 KiB
C#
Raw Normal View History

using AIStudio.Provider.Anthropic;
2024-07-01 18:11:19 +00:00
using AIStudio.Provider.Mistral;
2024-04-20 15:06:50 +00:00
using AIStudio.Provider.OpenAI;
using AIStudio.Provider.SelfHosted;
2024-04-20 15:06:50 +00:00
namespace AIStudio.Provider;
2024-05-04 08:55:00 +00:00
/// <summary>
/// Enum for all available providers.
/// </summary>
2024-04-20 15:06:50 +00:00
public enum Providers
{
NONE,
2024-04-20 15:06:50 +00:00
OPEN_AI,
ANTHROPIC,
2024-07-01 18:11:19 +00:00
MISTRAL,
SELF_HOSTED,
2024-04-20 15:06:50 +00:00
}
2024-05-04 08:55:00 +00:00
/// <summary>
/// Extension methods for the provider enum.
/// </summary>
2024-04-20 15:06:50 +00:00
public static class ExtensionsProvider
{
2024-05-04 08:55:00 +00:00
/// <summary>
/// Returns the human-readable name of the provider.
/// </summary>
/// <param name="provider">The provider.</param>
/// <returns>The human-readable name of the provider.</returns>
2024-04-20 15:06:50 +00:00
public static string ToName(this Providers provider) => provider switch
{
Providers.NONE => "No provider selected",
2024-04-20 15:06:50 +00:00
Providers.OPEN_AI => "OpenAI",
Providers.ANTHROPIC => "Anthropic",
2024-07-01 18:11:19 +00:00
Providers.MISTRAL => "Mistral",
2024-04-20 15:06:50 +00:00
Providers.SELF_HOSTED => "Self-hosted",
2024-04-20 15:06:50 +00:00
_ => "Unknown",
};
2024-05-04 08:55:00 +00:00
/// <summary>
/// Creates a new provider instance based on the provider value.
/// </summary>
/// <param name="provider">The provider value.</param>
/// <param name="instanceName">The used instance name.</param>
/// <param name="hostname">The hostname of the provider.</param>
2024-05-04 08:55:00 +00:00
/// <returns>The provider instance.</returns>
public static IProvider CreateProvider(this Providers provider, string instanceName, string hostname = "http://localhost:1234") => provider switch
2024-04-20 15:06:50 +00:00
{
Providers.OPEN_AI => new ProviderOpenAI { InstanceName = instanceName },
Providers.ANTHROPIC => new ProviderAnthropic { InstanceName = instanceName },
2024-07-01 18:11:19 +00:00
Providers.MISTRAL => new ProviderMistral { InstanceName = instanceName },
2024-04-20 15:06:50 +00:00
Providers.SELF_HOSTED => new ProviderSelfHosted(hostname) { InstanceName = instanceName },
2024-04-20 15:06:50 +00:00
_ => new NoProvider(),
};
}