Skip to content

Commit ce81870

Browse files
Merge pull request #39 from wisedev-code/feat/pre-process-document-to-improve-KM
feat: more KM improv
2 parents fac2ce4 + abc5db3 commit ce81870

File tree

18 files changed

+754
-33
lines changed

18 files changed

+754
-33
lines changed

Examples/Examples.SimpleConsole/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using MaIN.Core;
22
using MaIN.Core.Hub;
3+
using MaIN.Domain.Entities;
34

45
MaINBootstrapper.Initialize();
56

@@ -8,3 +9,5 @@ await AIHub.Chat()
89
.WithMessage("Hello, World!")
910
.CompleteAsync(interactive: true);
1011

12+
13+

Examples/Examples/Chat/ChatWithFilesExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public async Task Start()
1111
List<string> files = ["./Files/Nicolaus_Copernicus.pdf", "./Files/Galileo_Galilei.pdf"];
1212

1313
var result = await AIHub.Chat()
14-
.WithModel("gemma2:2b")
14+
.WithModel("gemma3:4b")
1515
.WithMessage("You have 2 documents in memory. Whats the difference of work between Galileo and Copernicus?. Give answer based on the documents.")
1616
.WithFiles(files)
1717
.CompleteAsync();

Examples/Examples/Chat/ChatWithFilesFromStreamExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task Start()
3434
}
3535

3636
var result = await AIHub.Chat()
37-
.WithModel("gemma2:2b")
37+
.WithModel("qwen2.5:0.5b")
3838
.WithMessage("You have 2 documents in memory. Whats the difference of work between Galileo and Copernicus?. Give answer based on the documents.")
3939
.WithFiles(fileStreams)
4040
.CompleteAsync();

Releases/0.1.5.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.1.5 release
2+
3+
- Enable pre processing of documents, it can greatly improve KM performance on small models

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.1.4</version>
5+
<version>0.1.5</version>
66
<authors>Wisedev</authors>
77
<owners>Wisedev</owners>
88
<icon>favicon.png</icon>

src/MaIN.Core/Hub/Contexts/ChatContext.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using MaIN.Domain.Entities;
22
using MaIN.Domain.Models;
3+
using MaIN.Services.Constants;
34
using MaIN.Services.Dtos;
45
using MaIN.Services.Services.Abstract;
56
using MaIN.Services.Services.Models;
@@ -10,8 +11,9 @@ namespace MaIN.Core.Hub.Contexts;
1011
public class ChatContext
1112
{
1213
private readonly IChatService _chatService;
14+
private bool _preProcess;
1315
private Chat _chat { get; set; }
14-
private List<FileInfo> _files { get; set; }
16+
private List<FileInfo> _files { get; set; } = [];
1517

1618
internal ChatContext(IChatService chatService)
1719
{
@@ -84,7 +86,7 @@ public ChatContext WithSystemPrompt(string systemPrompt)
8486
return this;
8587
}
8688

87-
public ChatContext WithFiles(List<FileStream> fileStreams)
89+
public ChatContext WithFiles(List<FileStream> fileStreams, bool preProcess = false)
8890
{
8991
var files = fileStreams.Select(p => new FileInfo()
9092
{
@@ -94,17 +96,19 @@ public ChatContext WithFiles(List<FileStream> fileStreams)
9496
StreamContent = p
9597
}).ToList();
9698

99+
_preProcess = preProcess;
97100
_files = files;
98101
return this;
99102
}
100103

101-
public ChatContext WithFiles(List<FileInfo> files)
104+
public ChatContext WithFiles(List<FileInfo> files, bool preProcess = false)
102105
{
103106
_files = files;
107+
_preProcess = preProcess;
104108
return this;
105109
}
106110

107-
public ChatContext WithFiles(List<string> filePaths)
111+
public ChatContext WithFiles(List<string> filePaths, bool preProcess = false)
108112
{
109113
var files = filePaths.Select(p => new FileInfo()
110114
{
@@ -113,6 +117,7 @@ public ChatContext WithFiles(List<string> filePaths)
113117
Extension = Path.GetExtension(p)
114118
}).ToList();
115119

120+
_preProcess = preProcess;
116121
_files = files;
117122
return this;
118123
}
@@ -135,6 +140,11 @@ public async Task<ChatResult> CompleteAsync(
135140
throw new InvalidOperationException("Chat has no messages."); //TODO good candidate for domain exception
136141
}
137142
_chat.Messages.Last().Files = _files;
143+
if(_preProcess)
144+
{
145+
_chat.Messages.Last().Properties.Add(ServiceConstants.Messages.PreProcessProperty, string.Empty);
146+
}
147+
138148
if (!await ChatExists(_chat.Id))
139149
{
140150
await _chatService.Create(_chat);

src/MaIN.Core/MaIN.Core.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
<ItemGroup>
1010
<PackageReference Include="GTranslate" Version="2.2.0" />
11-
<PackageReference Include="HtmlAgilityPack" Version="1.11.72" />
11+
<PackageReference Include="HtmlAgilityPack" Version="1.12.1" />
1212
<PackageReference Include="LLamaSharp" Version="0.23.0" />
1313
<PackageReference Include="LLamaSharp.Backend.Cuda12" Version="0.23.0" />
1414
<PackageReference Include="LLamaSharp.kernel-memory" Version="0.23.0" />
15-
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.1" />
16-
<PackageReference Include="Microsoft.KernelMemory" Version="0.96.250120.1" />
15+
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.3" />
16+
<PackageReference Include="Microsoft.KernelMemory" Version="0.98.250324.1" />
1717
<PackageReference Include="Microsoft.SemanticKernel" Version="1.30.0" />
1818
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Memory" Version="1.30.0-alpha" />
1919
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />

src/MaIN.Domain/Entities/Agents/AgentSource/AgentFileSourceDetails.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ public class AgentFileSourceDetails : AgentSourceDetailsBase, IAgentSource
44
{
55
public required string Path { get; init; }
66
public required string Name { get; init; }
7+
public bool PreProcess { get; init; } = false;
78
}

src/MaIN.Services/Constants/ServiceConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static class ApiUrls
2020
public static class Messages
2121
{
2222
public const string GeneratedImageContent = "Generated Image:";
23+
public const string PreProcessProperty = "Pre_Process";
2324
}
2425

2526
public static class Defaults

src/MaIN.Services/MaIN.Services.csproj

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@
1414

1515
<ItemGroup>
1616
<PackageReference Include="GTranslate" Version="2.2.0" />
17-
<PackageReference Include="HtmlAgilityPack" Version="1.11.72" />
17+
<PackageReference Include="HtmlAgilityPack" Version="1.12.1" />
1818
<PackageReference Include="LLamaSharp" Version="0.23.0" />
1919
<PackageReference Include="LLamaSharp.Backend.Cuda12" Version="0.23.0" />
2020
<PackageReference Include="LLamaSharp.kernel-memory" Version="0.23.0" />
21-
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.1" />
22-
<PackageReference Include="Microsoft.KernelMemory" Version="0.96.250120.1" />
23-
<PackageReference Include="Microsoft.SemanticKernel" Version="1.30.0" />
24-
<PackageReference Include="Microsoft.SemanticKernel.Plugins.Memory" Version="1.30.0-alpha" />
21+
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.3" />
22+
<PackageReference Include="Microsoft.KernelMemory" Version="0.98.250324.1" />
2523
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
2624
<PackageReference Include="Tesseract" Version="5.2.0" />
2725
<PackageReference Include="Tesseract.Data.English" Version="4.0.0" />

0 commit comments

Comments
 (0)