Open AI

Description

The OpenAI provider integrates OpenAI chat + embeddings behind IFlexAIProvider.

Provider capabilities (based on the implementation):

  • Chat completions: ChatAsync(...)

  • Streaming chat: ChatStreamAsync(...)

  • Embeddings: EmbedAsync(...) (supports optional dimensions and end-user identifier)

Important concepts

  • Application code should depend on IFlexAIProvider.

  • Flex generates Queries/Handlers that consume IFlexAIProvider; you only register the provider.

  • Defaults (when not overridden by request/config):

    • Chat model: gpt-4o

    • Embedding model: text-embedding-3-small

Configuration in DI

// Registers IFlexAIProvider / IFlexAIProviderBridge
services.AddFlexOpenAI(configuration);

appsettings.json

Configuration section: FlexBase:AI:OpenAI

Examples (template-based)

These examples mirror the generated Query and PostBus handler templates. You do not register these types manually.

Query: generate a completion

PostBus handler: generate a completion

Provider considerations

  • Embeddings: EmbedAsync(...) supports setting Dimensions (when the selected embedding model supports it).

  • Observability: the implementation logs duration + token usage when available.

  • Secrets: keep ApiKey in user-secrets/KeyVault/etc. (do not commit to source control).

Last updated