using NewLife.Studio.AI.Providers;
namespace NewLife.Studio.AI;
/// <summary>AI Provider 工厂</summary>
public static class AIProviderFactory
{
/// <summary>根据 ProviderType 创建对应的 IAIProvider</summary>
public static IAIProvider Create(HttpClient httpClient, string providerType, string endpoint, string apiKey, string model)
{
return providerType.ToLowerInvariant() switch
{
"openai" => new OpenAIProvider(httpClient, endpoint, apiKey, model),
"azure" => new OpenAIProvider(httpClient, endpoint, apiKey, model), // Azure 也是兼容 API
"ollama" => new OpenAIProvider(httpClient, endpoint, apiKey, model), // Ollama 也是兼容 API
_ => throw new ArgumentException($"Unknown provider type: {providerType}")
};
}
}
|