Class ChatClientProvider
- Namespace
- IntentSharp.Extensions.AI
- Assembly
- IntentSharp.Extensions.AI.dll
Runs IntentSharp on any Microsoft.Extensions.AI Microsoft.Extensions.AI.IChatClient: Azure OpenAI, OpenAI, Ollama, the Agent Framework and every other backend that implements the abstraction. The chat client only carries each request and its reply; the checks on the result, further attempts, the judge and memory work as they do with the built-in providers.
var client = new IntentClientBuilder()
.UseChatClient(chatClient)
.Build();
public sealed class ChatClientProvider : IAIProvider
- Inheritance
-
objectChatClientProvider
- Implements
- Inherited Members
-
object.Equals(object)object.Equals(object, object)object.GetHashCode()object.GetType()object.ReferenceEquals(object, object)object.ToString()
- Extension Methods
Remarks
Each AIRequest becomes a system message (when SystemPrompt is set) followed by the request's messages, and Microsoft.Extensions.AI.ChatOptions carrying the model, output token ceiling, temperature and response format (ForJsonSchema(JsonElement, string, string) for a JSON schema, Microsoft.Extensions.AI.ChatResponseFormat.Json for any JSON object, none for text). Request tags are never sent.
Failures thrown by the chat client are translated to the IntentSharp provider exceptions so the client's fallback
rules apply unchanged: an HTTP status found on the exception (StatusCode, or a
public Status or StatusCode property as on the OpenAI and Azure SDK exceptions) decides the type, and
a transport failure or a timeout inside the chat client is transient. This provider does not retry by itself; wrap
the chat client in one that retries, or rely on the fallback provider.
The caller owns the chat client and the embedding generator. Disposing the IntentClient does not dispose them.
Constructors
- ChatClientProvider(IChatClient, IEmbeddingGenerator<string, Embedding<float>>?, string?, string?, ILogger?)
Wraps the chat client, and optionally an embedding generator, as a provider. The name and the default model come from the chat client's metadata unless they are given here.
Fields
- DefaultName
The provider name used when neither the constructor nor the client's metadata supplies one.
Properties
- ChatClient
The wrapped chat client.
- DefaultModel
Model used when a request does not name one.
- Name
Stable provider name used in results, rate limiting and logs (for example "OpenAI").
- SupportsEmbeddings
True when EmbedAsync(string, CancellationToken) is implemented.
Methods
- CompleteAsync(AIRequest, CancellationToken)
Sends a chat-style request and returns the model's reply.
- EmbedAsync(string, CancellationToken)
Returns an embedding vector for the text. Throws NotSupportedException when SupportsEmbeddings is false.