< Summary

Information
Class: Intentum.AI.AzureOpenAI.AzureOpenAIOptions
Assembly: Intentum.AI.AzureOpenAI
File(s): /home/runner/work/Intentum/Intentum/src/Intentum.AI.AzureOpenAI/AzureOpenAIOptions.cs
Line coverage
50%
Covered lines: 14
Uncovered lines: 14
Coverable lines: 28
Total lines: 44
Line coverage: 50%
Branch coverage
50%
Covered branches: 8
Total branches: 16
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%88100%
FromEnvironment()0%880%

File(s)

/home/runner/work/Intentum/Intentum/src/Intentum.AI.AzureOpenAI/AzureOpenAIOptions.cs

#LineLine coverage
 1using JetBrains.Annotations;
 2
 3namespace Intentum.AI.AzureOpenAI;
 4
 5public sealed class AzureOpenAIOptions
 6{
 7    private const string UrlTrailingSlash = "/";
 8
 129    public required string Endpoint { get; init; }
 1110    public required string ApiKey { get; init; }
 1711    public string EmbeddingDeployment { get; init; } = "embedding";
 1612    public string ApiVersion { get; init; } = "2023-05-15";
 13
 14    public void Validate()
 615    {
 616        if (string.IsNullOrWhiteSpace(Endpoint))
 117            throw new ArgumentException("AzureOpenAI Endpoint is required.");
 518        if (string.IsNullOrWhiteSpace(ApiKey))
 119            throw new ArgumentException("AzureOpenAI ApiKey is required.");
 420        if (string.IsNullOrWhiteSpace(EmbeddingDeployment))
 121            throw new ArgumentException("AzureOpenAI EmbeddingDeployment is required.");
 322        if (string.IsNullOrWhiteSpace(ApiVersion))
 123            throw new ArgumentException("AzureOpenAI ApiVersion is required.");
 224    }
 25
 26    [UsedImplicitly]
 27    public static AzureOpenAIOptions FromEnvironment()
 028    {
 029        var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
 030            ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set. Copy .env.example to .env and set 
 031        var apiKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY")
 032            ?? throw new InvalidOperationException("AZURE_OPENAI_API_KEY is not set. Copy .env.example to .env and set A
 33
 034        var normalizedEndpoint = endpoint.TrimEnd(UrlTrailingSlash[0]) + UrlTrailingSlash;
 35
 036        return new AzureOpenAIOptions
 037        {
 038            Endpoint = normalizedEndpoint,
 039            ApiKey = apiKey,
 040            EmbeddingDeployment = Environment.GetEnvironmentVariable("AZURE_OPENAI_EMBEDDING_DEPLOYMENT") ?? "embedding"
 041            ApiVersion = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_VERSION") ?? "2023-05-15"
 042        };
 043    }
 44}