< Summary

Information
Class: Intentum.AI.OpenAI.OpenAIOptions
Assembly: Intentum.AI.OpenAI
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.AI.OpenAI/OpenAIOptions.cs
Line coverage
45%
Covered lines: 11
Uncovered lines: 13
Coverable lines: 24
Total lines: 39
Line coverage: 45.8%
Branch coverage
50%
Covered branches: 6
Total branches: 12
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Validate()100%66100%
FromEnvironment()0%660%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.AI.OpenAI/OpenAIOptions.cs

#LineLine coverage
 1namespace Intentum.AI.OpenAI;
 2
 3public sealed class OpenAIOptions
 4{
 5    private const string DefaultBaseUrl = "https://api.openai.com/v1/";
 6    private const string UrlTrailingSlash = "/";
 7
 218    public required string ApiKey { get; init; }
 309    public string EmbeddingModel { get; init; } = "text-embedding-3-large";
 1810    public string? BaseUrl { get; init; }
 11
 12    public void Validate()
 1013    {
 1014        if (string.IsNullOrWhiteSpace(ApiKey))
 215            throw new ArgumentException("OpenAI ApiKey is required.");
 816        if (string.IsNullOrWhiteSpace(EmbeddingModel))
 117            throw new ArgumentException("OpenAI EmbeddingModel is required.");
 718        if (string.IsNullOrWhiteSpace(BaseUrl))
 319            throw new ArgumentException("OpenAI BaseUrl is required.");
 420    }
 21
 22    public static OpenAIOptions FromEnvironment()
 023    {
 024        var apiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY")
 025            ?? throw new InvalidOperationException("OPENAI_API_KEY is not set. Copy .env.example to .env and set OPENAI_
 26
 027        var baseUrl = Environment.GetEnvironmentVariable("OPENAI_BASE_URL")
 028            ?? DefaultBaseUrl;
 29
 030        var normalizedBaseUrl = baseUrl.TrimEnd(UrlTrailingSlash[0]) + UrlTrailingSlash;
 31
 032        return new OpenAIOptions
 033        {
 034            ApiKey = apiKey,
 035            EmbeddingModel = Environment.GetEnvironmentVariable("OPENAI_EMBEDDING_MODEL") ?? "text-embedding-3-large",
 036            BaseUrl = normalizedBaseUrl
 037        };
 038    }
 39}