Skip to content

Commit f6bc2aa

Browse files
MadzionatorPiotr Stachaczynski
andauthored
Deepseek integration (#69)
* Add DeepSeek LLM backend integration * Add DeepSeek models and update image gen factory * Add DeepSeek reasoning support * Improve method to fetch current models for OpenAi compatible models * versioning * PR fixes * PR fixes 2 * infer fix + clean --------- Co-authored-by: Piotr Stachaczynski <piotr.stachaczynski@priva.com>
1 parent 7c06b0f commit f6bc2aa

18 files changed

Lines changed: 218 additions & 19 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
4+
namespace Examples;
5+
6+
public class ChatWithReasoningDeepSeekExample : IExample
7+
{
8+
public async Task Start()
9+
{
10+
DeepSeekExample.Setup(); //We need to provide DeepSeek API key
11+
Console.WriteLine("(DeepSeek) ChatExample with reasoning is running!");
12+
13+
await AIHub.Chat()
14+
.WithModel("deepseek-reasoner") // a model that supports reasoning
15+
.WithMessage("What chill pc game do you recommend?")
16+
.CompleteAsync(interactive: true);
17+
}
18+
}

Examples/Examples/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static void RegisterExamples(IServiceCollection services)
6666
services.AddTransient<ChatExampleGemini>();
6767
services.AddTransient<ChatWithImageGenGeminiExample>();
6868
services.AddTransient<ChatWithFilesExampleGemini>();
69+
services.AddTransient<ChatWithReasoningDeepSeekExample>();
6970
}
7071

7172
async Task RunSelectedExample(IServiceProvider serviceProvider)
@@ -151,6 +152,7 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
151152
("\u25a0 Gemini Chat", serviceProvider.GetRequiredService<ChatExampleGemini>()),
152153
("\u25a0 Gemini Chat with image", serviceProvider.GetRequiredService<ChatWithImageGenGeminiExample>()),
153154
("\u25a0 Gemini Chat with files", serviceProvider.GetRequiredService<ChatWithFilesExampleGemini>()),
155+
("\u25a0 DeepSeek Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningDeepSeekExample>()),
154156
("\u25a0 McpClient example", serviceProvider.GetRequiredService<McpExample>()),
155157
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>())
156158

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using MaIN.Core;
2+
using MaIN.Domain.Configuration;
3+
4+
namespace Examples.Utils;
5+
6+
public class DeepSeekExample
7+
{
8+
public static void Setup()
9+
{
10+
MaINBootstrapper.Initialize(configureSettings: (options) =>
11+
{
12+
options.BackendType = BackendType.DeepSeek;
13+
options.DeepSeekKey = "<YOUR_DEEPSEEK_KEY>";
14+
});
15+
}
16+
}

Releases/0.3.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 0.3.10 release
2+
3+
DeepSeek integration has been added, bringing reasoning support.
4+
The method for fetching current models across all OpenAI-compatible services has also been improved.

src/MaIN.Core/.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>MaIN.NET</id>
5-
<version>0.2.9</version>
5+
<version>0.3.0</version>
66
<authors>Wisedev</authors>
77
<owners>Wisedev</owners>
88
<icon>favicon.png</icon>

src/MaIN.Domain/Configuration/MaINSettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class MaINSettings
1010
public string? ImageGenUrl { get; set; }
1111
public string? OpenAiKey { get; set; }
1212
public string? GeminiKey { get; set; }
13+
public string? DeepSeekKey { get; set; }
1314
public MongoDbSettings? MongoDbSettings { get; set; }
1415
public FileSystemSettings? FileSystemSettings { get; set; }
1516
public SqliteSettings? SqliteSettings { get; set; }
@@ -20,5 +21,6 @@ public enum BackendType
2021
{
2122
Self = 0,
2223
OpenAi = 1,
23-
Gemini = 2
24+
Gemini = 2,
25+
DeepSeek = 3,
2426
}

src/MaIN.Domain/Models/SupportedModels.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ public static Model GetEmbeddingModel() =>
195195
DownloadUrl = "https://huggingface.co/Inza124/Nomic/resolve/main/Nomic-maIN.gguf?download=true",
196196
};
197197

198+
public static bool IsModelSupported(string name) =>
199+
Models.Any(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)
200+
|| x.Name.Replace(':', '-').Equals(name,
201+
StringComparison.InvariantCultureIgnoreCase));
202+
198203
public static Model GetModel(string path, string? name)
199204
{
200205
var model = Models.FirstOrDefault(x => x.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@
208208
? AIHub.Chat().WithCustomModel(model: Utils.Model!, path: Utils.Path)
209209
: AIHub.Chat().WithModel(Utils.Model!); //If that grows with different chat types we can consider switch ex
210210
211-
if (!Utils.OpenAi)
211+
if (Utils.DeepSeek)
212+
{
213+
_reasoning = Utils.Model!.ToLower().Contains("reasoner");
214+
Utils.Reason = _reasoning;
215+
}
216+
else if (!Utils.OpenAi)
212217
{
213218
_reasoning = !Utils.Visual && KnownModels.GetModel(Utils.Model!).HasReasoning();
214219
Utils.Reason = _reasoning;

src/MaIN.InferPage/Program.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System.Net.Mime;
12
using MaIN.Core;
23
using MaIN.Domain.Configuration;
4+
using MaIN.Domain.Models;
35
using Microsoft.FluentUI.AspNetCore.Components;
46
using MaIN.InferPage.Components;
57
using Utils = MaIN.InferPage.Utils;
@@ -57,6 +59,12 @@
5759
apiKeyVariable = "GEMINI_API_KEY";
5860
apiName = "Gemini";
5961
break;
62+
63+
case "deepseek":
64+
Utils.DeepSeek = true;
65+
apiKeyVariable = "DEEPSEEK_API_KEY";
66+
apiName = "Deepseek";
67+
break;
6068
}
6169

6270
var key = Environment.GetEnvironmentVariable(apiKeyVariable);
@@ -88,8 +96,21 @@
8896
settings.BackendType = BackendType.Gemini;
8997
});
9098
}
99+
else if (Utils.DeepSeek)
100+
{
101+
builder.Services.AddMaIN(builder.Configuration, settings =>
102+
{
103+
settings.BackendType = BackendType.DeepSeek;
104+
});
105+
}
91106
else
92107
{
108+
if (Utils.Path == null && !KnownModels.IsModelSupported(Utils.Model!))
109+
{
110+
Console.WriteLine($"Model: {Utils.Model} is not supported");
111+
Environment.Exit(0);
112+
}
113+
93114
builder.Services.AddMaIN(builder.Configuration);
94115
}
95116

src/MaIN.InferPage/Utils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class Utils
99
private static readonly string[] VisualModels = ["FLUX.1_Shnell", "FLUX.1", "dall-e-3", "dall-e", "imagen", "imagen-3"]; //user might type different names
1010
public static bool OpenAi { get; set; }
1111
public static bool Gemini { get; set; }
12+
public static bool DeepSeek { get; set; }
1213
public static string? Path { get; set; }
1314
public static bool Reason { get; set; }
1415
}

0 commit comments

Comments
 (0)