Method GetService
GetService(Type, object?)
Resolves, in order: this when serviceKey is null &&
serviceType.IsInstanceOfType(this); ChatClientMetadata with
ProviderName "onnxruntime-genai" and DefaultModelId =
ModelId; ChatModelInfo; ChatClientStatistics;
IChatModelHost; and, while this client holds the model, Model,
Tokenizer and Config.
This method is the entire integration surface for three downstream consumers and is
a contract, not an implementation detail: Semantic Kernel's GetModelId() is literally
GetService<ChatClientMetadata>()?.DefaultModelId, Agent Framework's
ChatClientAgent avoids double-wrapping by calling
GetService<FunctionInvokingChatClient>(), and MEAI's own
GetRequiredService<T>() goes through it. Returning the raw Model is also
what lets a consumer build OnnxRuntimeGenAIChatClient, MultiModalProcessor or
LoRA Adapters themselves without sub-project 4 wrapping any of it.
The three native objects are returned only while this client holds a lease - which, with the conversation cache on, is from the first turn until the cache is dropped. A model the host may dispose under the caller is never handed out.
public object? GetService(Type serviceType, object? serviceKey = null)
Parameters
serviceTypeTypeThe requested type.
serviceKeyobjectMust be null; a keyed request resolves nothing here.
Returns
- object
The service, or null.
Exceptions
- ArgumentNullException
serviceTypeis null.