namespace MS.Microservice.AI.Core; /// /// Root configuration section for the AI module. Binds to the AI key /// in appsettings.json or equivalent configuration source. /// public sealed class AIOptions { /// The configuration section name: AI. public const string SectionName = "AI"; /// Registered provider configurations, keyed by provider name (case-insensitive). public IDictionary Providers { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase); /// Per-capability model configurations. public AIModelsOptions Models { get; set; } = new(); /// Fallback provider name used when a model entry does not specify its own provider. public string? DefaultProvider { get; set; } } /// /// Model configurations grouped by capability. Each dictionary maps scenario /// keys (case-insensitive) to their model options. /// public sealed class AIModelsOptions { /// Chat / text completion model scenarios. public IDictionary Chat { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase); /// Text-to-speech model scenarios. public IDictionary Tts { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase); /// Speech recognition model scenarios. public IDictionary Asr { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase); /// Image generation model scenarios. public IDictionary ImageGeneration { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase); /// Image edit model scenarios. public IDictionary ImageEdit { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase); } /// /// Configuration for a single AI provider. /// public sealed class AIProviderRegistrationOptions { /// When false, the provider is skipped during validation and registration. public bool Enabled { get; set; } = true; /// API key or bearer token for authentication. public string? ApiKey { get; set; } /// Provider-neutral secret name used to resolve the API key when is empty. public string? ApiKeySecretName { get; set; } /// Base URL for the provider's API. Falls back to the provider's well-known default when empty. public string? BaseAddress { get; set; } /// /// Per-endpoint overrides (e.g. MultimodalGeneration for Qwen reference-image editing). /// When a key is present, the provider uses the mapped absolute URL instead of the default /// relative path derived from . /// public IDictionary Endpoints { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase); /// Additional HTTP headers sent with every request to this provider. public IDictionary Headers { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase); /// Default request timeout in seconds. Individual models can override this. public int TimeoutSeconds { get; set; } = 100; /// Default maximum retry attempts for transient failures. Individual models can override this. public int MaxRetryAttempts { get; set; } = 2; /// Maximum concurrent requests shared by this provider's built-in capabilities within one service container. public int ConcurrencyLimit { get; set; } = 8; /// Maximum bytes buffered for a successful non-streaming response. public long MaxResponseBytes { get; set; } = 64L * 1024 * 1024; /// Maximum bytes buffered for an HTTP error response, including streaming handshakes. public long MaxErrorResponseBytes { get; set; } = 64L * 1024; /// Maximum UTF-16 characters in any streaming response line, excluding its CR/LF terminator. public int MaxStreamLineCharacters { get; set; } = 1024 * 1024; } /// /// Configuration for a chat / text completion model scenario. /// public sealed class AIChatModelOptions { /// The provider to use for this scenario. public string Provider { get; set; } = string.Empty; /// The model identifier (e.g. gpt-4.1-mini). public string Model { get; set; } = string.Empty; /// Default sampling temperature. public double? Temperature { get; set; } /// Default nucleus sampling parameter. public double? TopP { get; set; } /// Default maximum output tokens. public int? MaxOutputTokens { get; set; } /// Per-scenario timeout override in seconds. public int? TimeoutSeconds { get; set; } /// Per-scenario retry override. public int? MaxRetryAttempts { get; set; } } /// /// Configuration for a text-to-speech model scenario. /// public sealed class AITtsModelOptions { /// The provider to use for this scenario. public string Provider { get; set; } = string.Empty; /// The model identifier (e.g. gpt-4o-mini-tts). public string Model { get; set; } = string.Empty; /// Default voice (e.g. alloy, chelsie). public string? Voice { get; set; } /// Default audio format (e.g. mp3, wav). public string? ResponseFormat { get; set; } /// Default speech speed multiplier. public double? Speed { get; set; } /// Per-scenario timeout override in seconds. public int? TimeoutSeconds { get; set; } /// Per-scenario retry override. public int? MaxRetryAttempts { get; set; } } /// /// Configuration for a speech recognition model scenario. /// public sealed class AIAsrModelOptions { /// The provider to use for this scenario. public string Provider { get; set; } = string.Empty; /// The model identifier (e.g. whisper-1). public string Model { get; set; } = string.Empty; /// Default input language hint (ISO-639-1). public string? Language { get; set; } /// Default guiding prompt for transcription. public string? Prompt { get; set; } /// Default response format (e.g. json, verbose_json). public string? ResponseFormat { get; set; } /// Per-scenario timeout override in seconds. public int? TimeoutSeconds { get; set; } /// Per-scenario retry override. public int? MaxRetryAttempts { get; set; } } /// /// Configuration for an image generation or image edit model scenario. /// public sealed class AIImageModelOptions { /// The provider to use for this scenario. public string Provider { get; set; } = string.Empty; /// The model identifier (e.g. gpt-image-1). public string Model { get; set; } = string.Empty; /// Default number of images to generate. public int? Count { get; set; } /// Default output dimensions (e.g. 1024x1024). public string? Size { get; set; } /// Default quality setting (e.g. standard, hd). public string? Quality { get; set; } /// Default response format (e.g. url, b64_json). public string? ResponseFormat { get; set; } /// Per-scenario timeout override in seconds. public int? TimeoutSeconds { get; set; } /// Per-scenario retry override. public int? MaxRetryAttempts { get; set; } }