Skip to content

Commit 5b3c364

Browse files
committed
Add ProviderParamsFactory and wire inference params
Introduce ProviderParamsFactory to create IProviderInferenceParams based on BackendType. Update Home.razor to set the backend and inference params on the new chat context (casting to IChatConfigurationBuilder) before preserving message history, ensuring the correct provider settings are applied when switching models. Also simplify ChatService by using the null-coalescing assignment (chat.Backend ??= settings.BackendType) to default the backend.
1 parent 9ec7d2f commit 5b3c364

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using MaIN.Domain.Configuration;
2+
3+
namespace MaIN.Domain.Entities.ProviderParams;
4+
5+
public static class ProviderParamsFactory
6+
{
7+
public static IProviderInferenceParams Create(BackendType backend) => backend switch
8+
{
9+
BackendType.Self => new LocalInferenceParams(),
10+
BackendType.OpenAi => new OpenAiParams(),
11+
BackendType.DeepSeek => new DeepSeekParams(),
12+
BackendType.GroqCloud => new GroqCloudParams(),
13+
BackendType.Xai => new XaiParams(),
14+
BackendType.Gemini => new GeminiParams(),
15+
BackendType.Anthropic => new AnthropicParams(),
16+
BackendType.Ollama => new OllamaParams(),
17+
_ => new LocalInferenceParams()
18+
};
19+
}

src/MaIN.InferPage/Components/Pages/Home.razor

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@using MaIN.Core.Hub.Contexts.Interfaces.ChatContext
1010
@using MaIN.Domain.Configuration
1111
@using MaIN.Domain.Entities
12+
@using MaIN.Domain.Entities.ProviderParams
1213
@using MaIN.Domain.Exceptions
1314
@using MaIN.Domain.Models
1415
@using MaIN.Domain.Models.Abstract
@@ -309,7 +310,12 @@
309310
if (model != null)
310311
{
311312
var newCtx = AIHub.Chat().WithModel(model, imageGen: Utils.ImageGen);
312-
// Preserve history on model switch; cast is safe — ChatContext implements both interfaces.
313+
// Set backend and provider params before adding messages.
314+
// Cast is safe — ChatContext implements both IChatMessageBuilder and IChatConfigurationBuilder.
315+
((IChatConfigurationBuilder)newCtx)
316+
.WithBackend(Utils.BackendType)
317+
.WithInferenceParams(ProviderParamsFactory.Create(Utils.BackendType));
318+
// Preserve history on model switch.
313319
ctx = Chat.Messages.Count > 0
314320
? (IChatMessageBuilder)newCtx.WithMessages(Chat.Messages)
315321
: newCtx;

src/MaIN.Services/Services/ChatService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public async Task<ChatResult> Completions(
3737
{
3838
chat.ImageGen = true;
3939
}
40-
chat.Backend = chat.Backend ?? settings.BackendType;
40+
chat.Backend ??= settings.BackendType;
4141

4242
chat.Messages.Where(x => x.Type == MessageType.NotSet).ToList()
4343
.ForEach(x => x.Type = chat.Backend != BackendType.Self ? MessageType.CloudLLM : MessageType.LocalLLM);

0 commit comments

Comments
 (0)