Class IntentClientBuilder
- Namespace
- IntentSharp
- Assembly
- IntentSharp.dll
Fluent construction of an IntentClient.
var client = new IntentClientBuilder()
.UseAnthropic(Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY")!)
.UseOpenAIAsFallback(Environment.GetEnvironmentVariable("OPENAI_API_KEY")!)
.WithMemory(new SqliteSemanticMemory("intentsharp-memory.db"))
.Build();
public sealed class IntentClientBuilder
- Inheritance
-
objectIntentClientBuilder
- Inherited Members
-
object.Equals(object)object.Equals(object, object)object.GetHashCode()object.GetType()object.ReferenceEquals(object, object)object.ToString()
- Extension Methods
Constructors
- IntentClientBuilder()
Creates a builder with no provider and default IntentClientOptions; add a primary provider before calling Build().
Methods
- Build()
Builds the client. The license key is checked here, once. It is LicenseKey, or, when that is not set, the
INTENTSHARP_LICENSE_KEYenvironment variable. A paid key whose maintenance period ended before this build was released throws LicenseException (an evaluation key never fails this way), as do a missing key, an invalid key and an ended evaluation when FailWhenUnlicensed is set. Every other state builds the client and logs a notice.
- Configure(Action<IntentClientOptions>)
Changes the client options. The action runs at once, on the options the client will be built with; several calls apply in order. Build() validates the options and throws ArgumentOutOfRangeException for a value out of range.
- UseAnthropic(string, string?)
Uses Anthropic as the primary provider, named "Anthropic". Calling it again replaces the primary.
- UseAnthropicAsFallback(string, string?)
Uses Anthropic as the fallback provider, named "Anthropic". Calling it again replaces the fallback.
- UseFallbackProvider(IAIProvider)
Uses any provider as fallback for transient primary failures. Calling it again replaces the fallback. Its name must differ from the primary's.
- UseOpenAI(string, string?)
Uses OpenAI as the primary provider, named "OpenAI". Calling it again replaces the primary.
- UseOpenAIAsFallback(string, string?)
Uses OpenAI as the fallback provider, named "OpenAI". Calling it again replaces the fallback.
- UseProvider(IAIProvider)
Uses any provider as primary. Calling it again replaces the primary. Requests can name a provider (Provider), so the primary and the fallback must have different names.
- UseProvidersFromEnvironment(string?, string?)
Reads ANTHROPIC_API_KEY and OPENAI_API_KEY. When the Anthropic key is set, Anthropic becomes the primary (replacing any primary already set). When the OpenAI key is set, OpenAI becomes the primary if there is none yet, otherwise the fallback.
- WithCache(IRequestCache?)
Sets the request cache that identical requests are served from. Pass null for none, which is also the default without this call. UseCache and BypassCache still apply.
- WithHttpClientFactory(Func<string, HttpClient?>)
Supplies HttpClient instances by provider name (for IHttpClientFactory integration). A supplied client keeps its own timeout; see Timeout.
- WithJudge(IResultJudge?)
Sets a custom judge. Without one, a ModelJudge on the primary provider is used when judging is enabled.
- WithLicenseKey(string)
Sets LicenseKey. A null or blank key makes Build() read the
INTENTSHARP_LICENSE_KEYenvironment variable instead.
- WithLoggerFactory(ILoggerFactory)
Sets the logger factory for the client, its license notices, the default judge and the OpenAI and Anthropic providers this builder creates. Call it before the methods that add those providers, since they create them at once. Without a logger factory nothing is logged, license notices included.
- WithMemory(ISemanticMemory?)
Sets the memory. Pass null to disable recording. Without this call the client uses an InMemorySemanticMemory with word-overlap recall only; pass one constructed with an embedding provider to opt in to recall by meaning (one embeddings call per recorded request).
- WithRateLimiter(IRateLimiter?)
Sets the rate limiter that every completion and judge call waits on, for at most 30 seconds; a call that would wait longer fails as a transient provider error. EmbedAsync(string, CancellationToken) calls do not wait on it. Pass null for none, which is also the default without this call.