31 lines
1.4 KiB
C#
31 lines
1.4 KiB
C#
using Volcanic.AgenticCore.Abstractions.Extensions;
|
|
using Volcanic.AgenticCore.Abstractions.Providers;
|
|
|
|
namespace Volcanic.AgenticCore.Extensions.Anthropic;
|
|
|
|
/// <summary>Registers the <c>anthropic</c> provider (Messages API over SSE) with the session's model registry.</summary>
|
|
/// <param name="http">Optional <see cref="HttpClient"/>; when omitted a shared client without a request timeout is used.</param>
|
|
/// <param name="models">Model catalogue; defaults to <see cref="AnthropicModels.All"/>.</param>
|
|
/// <param name="apiKeySpec">API key spec (literal, <c>$ENV</c> or <c>!command</c>); defaults to <c>$ANTHROPIC_API_KEY</c>.</param>
|
|
public sealed class AnthropicProviderExtension(HttpClient? http = null, IReadOnlyList<Model>? models = null, string? apiKeySpec = null) : IExtension
|
|
{
|
|
public const string ExtensionName = "anthropic-provider";
|
|
|
|
public string Name => ExtensionName;
|
|
|
|
public ValueTask ActivateAsync(IExtensionApi api, CancellationToken cancellationToken)
|
|
{
|
|
api.RegisterProvider(new ProviderRegistration
|
|
{
|
|
Id = AnthropicModels.ProviderId,
|
|
Name = "Anthropic",
|
|
Api = AnthropicModels.ApiId,
|
|
BaseUrl = AnthropicModels.DefaultBaseUrl,
|
|
ApiKey = apiKeySpec ?? "$ANTHROPIC_API_KEY",
|
|
Models = models ?? AnthropicModels.All,
|
|
Stream = new AnthropicApi(http).StreamAsync,
|
|
});
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|