The problem it solves
The official LLM SDKs are built on async, IAsyncEnumerable and Span<T> —
patterns that are painful to consume through any reflection bridge. Connect's .NET facade collapses all of
that into a surface the bridge already handles well: plain properties, a blocking Complete, and a
Stream call that raises standard .NET events which the bridge maps onto Delphi event properties.
The result is that adding a live, streaming assistant to an existing VCL or FMX application is a few dozen
lines of ordinary Delphi — not a research project.
What you get
- Three providers, one interface. Anthropic, OpenAI and Azure OpenAI selected at construction:
TChatClient.Create(provider, apiKey, model).
- Blocking and streaming completion.
Complete for request/response, Stream for token-by-token output; both raise TokenReceived / Completed / Failed.
- Sampling controls.
Temperature, TopP and AddStop / ClearStops stop sequences; unset parameters are omitted so the provider default applies.
- Multi-turn conversations.
AddMessage(role, content) / ClearMessages — prior turns are sent as a proper multi-role message array.
- Embeddings.
IEmbeddingClient returning TArray<Single>, with batched embedding of a whole document in one request.
- Local models. Ollama, LM Studio and Foundry Local serve the OpenAI-compatible protocol, so provider
'openai' plus an Endpoint reaches a local model — the API key may be empty.
- Azure routing.
ApiVersion and deployment routing, plus a custom endpoint for gateways and proxies.
Production hardening, not a sample
Connect is a composable IChatClient pipeline built on Microsoft.Extensions.AI:
provider adapter → resilience → telemetry.
- Resilience. Transient
408/429/5xx retried with exponential backoff and jitter, honouring Retry-After; MaxRetries and RetryBaseDelayMs are configurable. A 429 caused by an exhausted quota or a hard billing limit is classified as permanent and fails immediately rather than stalling behind a retry loop that cannot succeed.
- Cost and token telemetry. Every call raises
UsageReported with input/output tokens, latency and a USD cost drawn from a configurable SetPrice table.
- Cancellation.
Cancel aborts the in-flight call.
- UI-thread safety.
CNCoreClr.AI.Threading.TUIDispatch wraps your handlers and marshals them onto the main thread via TThread.Queue.
- Response caching. Opt-in
CacheResponses returns a cached answer for a repeated identical Complete, keyed by model, sampling settings and messages. A cache hit skips the retry loop; telemetry stays outermost so UsageReported still fires.
Deployment notes
- Core edition requires .Net 8 or later (net6 and net7 are end-of-life). Framework edition requires .NET Framework 4.5 or later.
- The facade carries a small managed-only dependency closure (around 13 DLLs, no native code). Deploy the facade output folder alongside your executable.
- API keys stay the customer's responsibility — the facade never persists them.
- Requires a dotNetCore4Delphi licence (Core edition), or a .Net Runtime Library for Delphi licence for the Framework edition.