Skip to content

Commit b6056bc

Browse files
committed
Use LLMApiRegistry for API keys in IferPage Program.cs
Remove the old BackendType extension and centralize API key metadata in LLMApiRegistry (moved to MaIN.Domain.Models.Concrete). Program.cs now looks up the registry entry for each BackendType to read ApiKeyEnvName instead of calling GetApiKeyVariable. Updated numerous LLM and image service files (and McpService) to reference the new namespace. This change consolidates API key configuration and removes the duplicated extension method.
1 parent e0375fa commit b6056bc

File tree

15 files changed

+31
-28
lines changed

15 files changed

+31
-28
lines changed

src/MaIN.Core.UnitTests/ChatContextTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public async Task CompleteAsync_ShouldCallChatService()
8888
};
8989

9090

91-
_mockChatService.Setup(s => s.Completions(It.IsAny<Chat>(), It.IsAny<bool>(), It.IsAny<bool>(), null))
91+
_mockChatService.Setup(s => s.Completions(It.IsAny<Chat>(), It.IsAny<bool>(), It.IsAny<bool>(), null, It.IsAny<CancellationToken>()))
9292
.ReturnsAsync(chatResult);
9393

9494
_chatContext.WithMessage("User message");
@@ -98,7 +98,7 @@ public async Task CompleteAsync_ShouldCallChatService()
9898
var result = await _chatContext.CompleteAsync();
9999

100100
// Assert
101-
_mockChatService.Verify(s => s.Completions(It.IsAny<Chat>(), false, false, null), Times.Once);
101+
_mockChatService.Verify(s => s.Completions(It.IsAny<Chat>(), false, false, null, It.IsAny<CancellationToken>()), Times.Once);
102102
Assert.Equal(chatResult, result);
103103
}
104104

@@ -128,6 +128,6 @@ await _chatContext.WithModel(model)
128128
.CompleteAsync();
129129

130130
// Assert
131-
_mockChatService.Verify(s => s.Completions(It.Is<Chat>(c => c.ModelId == _testModelId && c.ModelInstance == model), It.IsAny<bool>(), It.IsAny<bool>(), null), Times.Once);
131+
_mockChatService.Verify(s => s.Completions(It.Is<Chat>(c => c.ModelId == _testModelId && c.ModelInstance == model), It.IsAny<bool>(), It.IsAny<bool>(), null, It.IsAny<CancellationToken>()), Times.Once);
132132
}
133133
}

src/MaIN.Domain/Extensions.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/MaIN.Services/Services/LLMService/Utils/LLMApiRegistry.cs renamed to src/MaIN.Domain/Models/Concrete/LLMApiRegistry.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace MaIN.Services.Services.LLMService.Utils;
1+
using MaIN.Domain.Configuration;
2+
3+
namespace MaIN.Domain.Models.Concrete;
24

35
public static class LLMApiRegistry
46
{
@@ -9,6 +11,18 @@ public static class LLMApiRegistry
911
public static readonly LLMApiRegistryEntry Anthropic = new("Anthropic", "ANTHROPIC_API_KEY");
1012
public static readonly LLMApiRegistryEntry Xai = new("Xai", "XAI_API_KEY");
1113
public static readonly LLMApiRegistryEntry Ollama = new("Ollama", "OLLAMA_API_KEY");
14+
15+
public static LLMApiRegistryEntry? GetEntry(BackendType backendType) => backendType switch
16+
{
17+
BackendType.OpenAi => OpenAi,
18+
BackendType.Gemini => Gemini,
19+
BackendType.DeepSeek => Deepseek,
20+
BackendType.GroqCloud => Groq,
21+
BackendType.Anthropic => Anthropic,
22+
BackendType.Xai => Xai,
23+
BackendType.Ollama => Ollama,
24+
_ => null
25+
};
1226
}
1327

1428
public record LLMApiRegistryEntry(string ApiName, string ApiKeyEnvName);

src/MaIN.InferPage/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using MaIN.Core;
2-
using MaIN.Domain;
32
using MaIN.Domain.Configuration;
3+
using MaIN.Domain.Models.Concrete;
44
using MaIN.Domain.Models.Abstract;
55
using Microsoft.FluentUI.AspNetCore.Components;
66
using MaIN.InferPage.Components;
@@ -34,7 +34,7 @@
3434

3535
if (Utils.BackendType != BackendType.Self)
3636
{
37-
var apiKeyVariable = Utils.BackendType.GetApiKeyVariable();
37+
var apiKeyVariable = LLMApiRegistry.GetEntry(Utils.BackendType)?.ApiKeyEnvName ?? string.Empty;
3838
var key = Environment.GetEnvironmentVariable(apiKeyVariable);
3939

4040
if (string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(apiKeyVariable))

src/MaIN.Services/Services/ImageGenServices/GeminiImageGenService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net.Http.Json;
88
using System.Text.Json.Serialization;
99
using MaIN.Domain.Exceptions;
10+
using MaIN.Domain.Models.Concrete;
1011
using MaIN.Services.Services.LLMService.Utils;
1112

1213
namespace MaIN.Services.Services.ImageGenServices;

src/MaIN.Services/Services/ImageGenServices/ImageGenDalleService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using MaIN.Domain.Configuration;
44
using MaIN.Domain.Entities;
55
using MaIN.Domain.Exceptions;
6+
using MaIN.Domain.Models.Concrete;
67
using MaIN.Services.Constants;
78
using MaIN.Services.Services.Abstract;
89
using MaIN.Services.Services.LLMService.Utils;

src/MaIN.Services/Services/ImageGenServices/XaiImageGenService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net.Http.Json;
88
using System.Text.Json;
99
using MaIN.Domain.Exceptions;
10+
using MaIN.Domain.Models.Concrete;
1011
using MaIN.Services.Services.LLMService.Utils;
1112

1213
namespace MaIN.Services.Services.ImageGenServices;

src/MaIN.Services/Services/LLMService/AnthropicService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using MaIN.Domain.Configuration;
1313
using MaIN.Domain.Entities.Tools;
1414
using MaIN.Domain.Exceptions;
15+
using MaIN.Domain.Models.Concrete;
1516
using MaIN.Services.Services.LLMService.Utils;
1617

1718
namespace MaIN.Services.Services.LLMService;

src/MaIN.Services/Services/LLMService/DeepSeekService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Text.Json;
1111
using System.Text.Json.Serialization;
1212
using MaIN.Domain.Exceptions;
13+
using MaIN.Domain.Models.Concrete;
1314
using MaIN.Services.Services.LLMService.Utils;
1415

1516
namespace MaIN.Services.Services.LLMService;

src/MaIN.Services/Services/LLMService/GeminiService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using MaIN.Domain.Entities;
1212
using MaIN.Domain.Exceptions;
1313
using MaIN.Domain.Models;
14+
using MaIN.Domain.Models.Concrete;
1415
using MaIN.Services.Services.LLMService.Utils;
1516
using MaIN.Services.Utils;
1617

0 commit comments

Comments
 (0)