| | | 1 | | using JetBrains.Annotations; |
| | | 2 | | |
| | | 3 | | namespace Intentum.AI.Mistral; |
| | | 4 | | |
| | | 5 | | public sealed class MistralOptions |
| | | 6 | | { |
| | | 7 | | private const string DefaultBaseUrl = "https://api.mistral.ai/v1/"; |
| | | 8 | | private const string UrlTrailingSlash = "/"; |
| | | 9 | | |
| | 10 | 10 | | public required string ApiKey { get; init; } |
| | 15 | 11 | | public string EmbeddingModel { get; init; } = "mistral-embed"; |
| | 8 | 12 | | public string? BaseUrl { get; init; } |
| | | 13 | | |
| | | 14 | | public void Validate() |
| | 5 | 15 | | { |
| | 5 | 16 | | if (string.IsNullOrWhiteSpace(ApiKey)) |
| | 1 | 17 | | throw new ArgumentException("Mistral ApiKey is required."); |
| | 4 | 18 | | if (string.IsNullOrWhiteSpace(EmbeddingModel)) |
| | 1 | 19 | | throw new ArgumentException("Mistral EmbeddingModel is required."); |
| | 3 | 20 | | if (string.IsNullOrWhiteSpace(BaseUrl)) |
| | 1 | 21 | | throw new ArgumentException("Mistral BaseUrl is required."); |
| | 2 | 22 | | } |
| | | 23 | | |
| | | 24 | | [UsedImplicitly] |
| | | 25 | | public static MistralOptions FromEnvironment() |
| | 0 | 26 | | { |
| | 0 | 27 | | var apiKey = Environment.GetEnvironmentVariable("MISTRAL_API_KEY") |
| | 0 | 28 | | ?? throw new InvalidOperationException("MISTRAL_API_KEY is not set. Copy .env.example to .env and set MISTRA |
| | | 29 | | |
| | 0 | 30 | | var baseUrl = Environment.GetEnvironmentVariable("MISTRAL_BASE_URL") |
| | 0 | 31 | | ?? DefaultBaseUrl; |
| | | 32 | | |
| | 0 | 33 | | var normalizedBaseUrl = baseUrl.TrimEnd(UrlTrailingSlash[0]) + UrlTrailingSlash; |
| | | 34 | | |
| | 0 | 35 | | return new MistralOptions |
| | 0 | 36 | | { |
| | 0 | 37 | | ApiKey = apiKey, |
| | 0 | 38 | | EmbeddingModel = Environment.GetEnvironmentVariable("MISTRAL_EMBEDDING_MODEL") ?? "mistral-embed", |
| | 0 | 39 | | BaseUrl = normalizedBaseUrl |
| | 0 | 40 | | }; |
| | 0 | 41 | | } |
| | | 42 | | } |