mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
91 lines
2.8 KiB
C#
91 lines
2.8 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
public sealed class TestConfiguration
|
|
{
|
|
private readonly IConfigurationRoot _configRoot;
|
|
private static TestConfiguration? s_instance;
|
|
|
|
private TestConfiguration(IConfigurationRoot configRoot)
|
|
{
|
|
this._configRoot = configRoot;
|
|
}
|
|
|
|
public static void Initialize(IConfigurationRoot configRoot)
|
|
{
|
|
s_instance = new TestConfiguration(configRoot);
|
|
}
|
|
|
|
public static AzureOpenAIConfig AzureOpenAI => LoadSection<AzureOpenAIConfig>();
|
|
|
|
public static ApplicationInsightsConfig ApplicationInsights => LoadSection<ApplicationInsightsConfig>();
|
|
|
|
public static GoogleAIConfig GoogleAI => LoadSection<GoogleAIConfig>();
|
|
|
|
public static HuggingFaceConfig HuggingFace => LoadSection<HuggingFaceConfig>();
|
|
|
|
public static MistralAIConfig MistralAI => LoadSection<MistralAIConfig>();
|
|
|
|
private static T LoadSection<T>([CallerMemberName] string? caller = null)
|
|
{
|
|
if (s_instance is null)
|
|
{
|
|
throw new InvalidOperationException(
|
|
"TestConfiguration must be initialized with a call to Initialize(IConfigurationRoot) before accessing configuration values.");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(caller))
|
|
{
|
|
throw new ArgumentNullException(nameof(caller));
|
|
}
|
|
|
|
return s_instance._configRoot.GetSection(caller).Get<T>() ??
|
|
throw new KeyNotFoundException($"Could not find configuration section {caller}");
|
|
}
|
|
|
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor.
|
|
public class AzureOpenAIConfig
|
|
{
|
|
public string ChatDeploymentName { get; set; }
|
|
public string ChatModelId { get; set; }
|
|
public string Endpoint { get; set; }
|
|
public string ApiKey { get; set; }
|
|
}
|
|
|
|
public class ApplicationInsightsConfig
|
|
{
|
|
public string ConnectionString { get; set; }
|
|
}
|
|
|
|
public class GoogleAIConfig
|
|
{
|
|
public string ApiKey { get; set; }
|
|
public string EmbeddingModelId { get; set; }
|
|
public GeminiConfig Gemini { get; set; }
|
|
|
|
public class GeminiConfig
|
|
{
|
|
public string ModelId { get; set; }
|
|
}
|
|
}
|
|
|
|
public class HuggingFaceConfig
|
|
{
|
|
public string ApiKey { get; set; }
|
|
public string ModelId { get; set; }
|
|
public string EmbeddingModelId { get; set; }
|
|
}
|
|
|
|
public class MistralAIConfig
|
|
{
|
|
public string ApiKey { get; set; }
|
|
public string ChatModelId { get; set; }
|
|
}
|
|
|
|
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor.
|
|
}
|