< Summary

Information
Class: Intentum.AI.Gemini.GeminiOptions
Assembly: Intentum.AI.Gemini
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.AI.Gemini/GeminiOptions.cs
Line coverage
45%
Covered lines: 11
Uncovered lines: 13
Coverable lines: 24
Total lines: 42
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.Gemini/GeminiOptions.cs

#LineLine coverage
 1using JetBrains.Annotations;
 2
 3namespace Intentum.AI.Gemini;
 4
 5public sealed class GeminiOptions
 6{
 7    private const string DefaultBaseUrl = "https://generativelanguage.googleapis.com/v1beta/";
 8    private const string UrlTrailingSlash = "/";
 9
 1110    public required string ApiKey { get; init; }
 1511    public string EmbeddingModel { get; init; } = "text-embedding-004";
 812    public string? BaseUrl { get; init; }
 13
 14    public void Validate()
 515    {
 516        if (string.IsNullOrWhiteSpace(ApiKey))
 117            throw new ArgumentException("Gemini ApiKey is required.");
 418        if (string.IsNullOrWhiteSpace(EmbeddingModel))
 119            throw new ArgumentException("Gemini EmbeddingModel is required.");
 320        if (string.IsNullOrWhiteSpace(BaseUrl))
 121            throw new ArgumentException("Gemini BaseUrl is required.");
 222    }
 23
 24    [UsedImplicitly]
 25    public static GeminiOptions FromEnvironment()
 026    {
 027        var apiKey = Environment.GetEnvironmentVariable("GEMINI_API_KEY")
 028            ?? throw new InvalidOperationException("GEMINI_API_KEY is not set. Copy .env.example to .env and set GEMINI_
 29
 030        var baseUrl = Environment.GetEnvironmentVariable("GEMINI_BASE_URL")
 031            ?? DefaultBaseUrl;
 32
 033        var normalizedBaseUrl = baseUrl.TrimEnd(UrlTrailingSlash[0]) + UrlTrailingSlash;
 34
 035        return new GeminiOptions
 036        {
 037            ApiKey = apiKey,
 038            EmbeddingModel = Environment.GetEnvironmentVariable("GEMINI_EMBEDDING_MODEL") ?? "text-embedding-004",
 039            BaseUrl = normalizedBaseUrl
 040        };
 041    }
 42}