An IEmbeddingGenerator<T1, T2> for OpenAI-compatible embeddings endpoints (OpenAI, Azure OpenAI, Ollama, Cloudflare Workers AI and others).
Object
Microsoft.Extensions.AI.IEmbeddingGenerator<string, Microsoft.Extensions.AI.Embedding<float>>
Microsoft.Extensions.AI.IEmbeddingGenerator
Namespace: Radzen
Assembly: Radzen.Blazor.dll
public sealed class OpenAICompatibleEmbeddingGenerator : Microsoft.Extensions.AI.IEmbeddingGenerator<string, Microsoft.Extensions.AI.Embedding<float>>, Microsoft.Extensions.AI.IEmbeddingGeneratorbuilder.Services.AddEmbeddingGenerator(services =>
new OpenAICompatibleEmbeddingGenerator(services.GetRequiredService<HttpClient>(), "https://api.openai.com/v1/embeddings", apiKey, defaultModel: "text-embedding-3-small"));Initializes a new instance of the OpenAICompatibleEmbeddingGenerator class.
public OpenAICompatibleEmbeddingGenerator(Net.Http.HttpClient httpClient, string endpoint, string apiKey, string apiKeyHeader, string defaultModel)
| Type | Name | Description |
|---|---|---|
| Net.Http.HttpClient | httpClient | The HttpClient used to send requests. It is not disposed by the generator. |
| string | endpoint | The embeddings URL, for example https://api.openai.com/v1/embeddings. A relative URL is resolved against the BaseAddress. |
| string | apiKey | The API key. When null or empty no authentication header is sent. |
| string | apiKeyHeader | The header that carries the API key. Authorization (the default) sends it as a bearer token. |
| string | defaultModel | The model used when ModelId is not set. |
Gets the metadata that describes the generator.
public Microsoft.Extensions.AI.EmbeddingGeneratorMetadata Metadata { get; }
| Type | Description |
|---|---|
| Microsoft.Extensions.AI.EmbeddingGeneratorMetadata | Gets the metadata that describes the generator. |
public Task<Microsoft.Extensions.AI.GeneratedEmbeddings<Microsoft.Extensions.AI.Embedding<float>>> GenerateAsync(IEnumerable<string> values, Microsoft.Extensions.AI.EmbeddingGenerationOptions options, Threading.CancellationToken cancellationToken)
| Type | Name | Description |
|---|---|---|
| IEnumerable<string> | values | |
| Microsoft.Extensions.AI.EmbeddingGenerationOptions | options | |
| Threading.CancellationToken | cancellationToken |
| Type | Description |
|---|---|
| Task<Microsoft.Extensions.AI.GeneratedEmbeddings<Microsoft.Extensions.AI.Embedding<float>>> |
public object GetService(Type serviceType, object serviceKey)
| Type | Name | Description |
|---|---|---|
| Type | serviceType | |
| object | serviceKey |
| Type | Description |
|---|---|
| object |