71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
namespace AnchorCli.Providers;
|
|
|
|
/// <summary>
|
|
/// Factory for creating provider instances based on endpoint or provider name.
|
|
/// </summary>
|
|
internal static class ProviderFactory
|
|
{
|
|
/// <summary>
|
|
/// Creates a token extractor based on the provider name.
|
|
/// </summary>
|
|
public static ITokenExtractor CreateTokenExtractor(string providerName)
|
|
{
|
|
return providerName.ToLowerInvariant() switch
|
|
{
|
|
"openrouter" => new OpenRouterTokenExtractor(),
|
|
"groq" => new GroqTokenExtractor(),
|
|
"ollama" => new OllamaTokenExtractor(),
|
|
_ => new GenericTokenExtractor()
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a token extractor by auto-detecting from the endpoint URL.
|
|
/// </summary>
|
|
public static ITokenExtractor CreateTokenExtractorForEndpoint(string endpoint)
|
|
{
|
|
if (string.IsNullOrEmpty(endpoint))
|
|
{
|
|
return new GenericTokenExtractor();
|
|
}
|
|
|
|
var url = endpoint.ToLowerInvariant();
|
|
|
|
if (url.Contains("openrouter"))
|
|
{
|
|
return new OpenRouterTokenExtractor();
|
|
}
|
|
|
|
if (url.Contains("groq"))
|
|
{
|
|
return new GroqTokenExtractor();
|
|
}
|
|
|
|
if (url.Contains("ollama") || url.Contains("localhost") || url.Contains("127.0.0.1"))
|
|
{
|
|
return new OllamaTokenExtractor();
|
|
}
|
|
|
|
return new GenericTokenExtractor();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a pricing provider based on the provider name.
|
|
/// Only OpenRouter has a pricing API currently.
|
|
/// </summary>
|
|
public static IPricingProvider? CreatePricingProvider(string providerName)
|
|
{
|
|
return providerName.ToLowerInvariant() switch
|
|
{
|
|
"openrouter" => new OpenRouterProvider(),
|
|
_ => null // Other providers don't have pricing APIs yet
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Determines if an endpoint is OpenRouter.
|
|
/// </summary>
|
|
public static bool IsOpenRouter(string endpoint) =>
|
|
!string.IsNullOrEmpty(endpoint) && endpoint.Contains("openrouter", StringComparison.OrdinalIgnoreCase);
|
|
}
|