Skip to content

Commit c1f0045

Browse files
committed
cleanup
1 parent 0d23b48 commit c1f0045

File tree

13 files changed

+44
-83
lines changed

13 files changed

+44
-83
lines changed

Examples/Examples/Utils/GeminiExampleSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static void Setup()
1010
MaINBootstrapper.Initialize(configureSettings: (options) =>
1111
{
1212
options.BackendType = BackendType.Gemini;
13-
options.GeminiKey = "<Gemini API Key>";
13+
options.GeminiKey = "<YOUR_GEMINI_KEY>";
1414
});
1515
}
1616
}

MaIN.Core.IntegrationTests/ChatTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public async Task Should_AnswerGameFromImage_ChatWithVision()
6666

6767
var result = await AIHub.Chat()
6868
.WithModel<Llama3_2_3b>()
69+
.WithMessage("What is the title of game?")
6970
.WithMemoryParams(new MemoryParams
7071
{
7172
AnswerTokens = 1000

MaIN.sln

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 18
4-
VisualStudioVersion = 18.1.11312.151 d18.0
4+
VisualStudioVersion = 18.1.11312.151
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaIN.Infrastructure", "src\MaIN.Infrastructure\MaIN.Infrastructure.csproj", "{84C09EF9-B9E3-4ACB-9BC3-DEFFC29D528F}"
77
EndProject
@@ -25,8 +25,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaIN.InferPage", "src\MaIN.
2525
EndProject
2626
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaIN.Core.IntegrationTests", "MaIN.Core.IntegrationTests\MaIN.Core.IntegrationTests.csproj", "{2C15062A-E9F6-47FC-A4CD-1190A49E3FE3}"
2727
EndProject
28-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{EC6B1BDC-EA44-41C9-86AB-ED9CF1AC35B7}"
29-
EndProject
3028
Global
3129
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3230
Debug|Any CPU = Debug|Any CPU
@@ -69,10 +67,6 @@ Global
6967
{2C15062A-E9F6-47FC-A4CD-1190A49E3FE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
7068
{2C15062A-E9F6-47FC-A4CD-1190A49E3FE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
7169
{2C15062A-E9F6-47FC-A4CD-1190A49E3FE3}.Release|Any CPU.Build.0 = Release|Any CPU
72-
{EC6B1BDC-EA44-41C9-86AB-ED9CF1AC35B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
73-
{EC6B1BDC-EA44-41C9-86AB-ED9CF1AC35B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
74-
{EC6B1BDC-EA44-41C9-86AB-ED9CF1AC35B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
75-
{EC6B1BDC-EA44-41C9-86AB-ED9CF1AC35B7}.Release|Any CPU.Build.0 = Release|Any CPU
7670
EndGlobalSection
7771
GlobalSection(SolutionProperties) = preSolution
7872
HideSolutionNode = FALSE
@@ -82,7 +76,6 @@ Global
8276
{46E6416B-1736-478C-B697-B37BB8E6A23E} = {53D24B04-279D-4D18-8829-EA0F57AE69F3}
8377
{75DEBB8A-75CD-44BA-9369-3916950428EF} = {28851935-517F-438D-BF7C-02FEB1A37A68}
8478
{2C15062A-E9F6-47FC-A4CD-1190A49E3FE3} = {53D24B04-279D-4D18-8829-EA0F57AE69F3}
85-
{EC6B1BDC-EA44-41C9-86AB-ED9CF1AC35B7} = {28851935-517F-438D-BF7C-02FEB1A37A68}
8679
EndGlobalSection
8780
GlobalSection(ExtensibilityGlobals) = postSolution
8881
SolutionGuid = {82494AB7-60FC-49E3-B37C-B9785FB0DE7A}

Test/Program.cs

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

Test/Test.csproj

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

Test/appsettings.json

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

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private async Task DownloadModelAsync(string url, string fileName, CancellationT
197197
}
198198
}
199199

200-
private async Task DownloadWithProgressAsync(HttpResponseMessage response, string filePath, string fileName, CancellationToken cancellationToken)
200+
private static async Task DownloadWithProgressAsync(HttpResponseMessage response, string filePath, string fileName, CancellationToken cancellationToken)
201201
{
202202
var totalBytes = response.Content.Headers.ContentLength;
203203
var totalBytesRead = 0L;
@@ -215,10 +215,13 @@ private async Task DownloadWithProgressAsync(HttpResponseMessage response, strin
215215

216216
while (true)
217217
{
218-
var bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length, cancellationToken);
219-
if (bytesRead == 0) break;
218+
var bytesRead = await contentStream.ReadAsync(buffer, cancellationToken);
219+
if (bytesRead == 0)
220+
{
221+
break;
222+
}
220223

221-
await fileStream.WriteAsync(buffer, 0, bytesRead, cancellationToken);
224+
await fileStream.WriteAsync(buffer.AsMemory(0, bytesRead), cancellationToken);
222225
totalBytesRead += bytesRead;
223226

224227
if (ShouldUpdateProgress(progressStopwatch))
@@ -317,7 +320,7 @@ private static void ShowProgress(long totalBytesRead, long? totalBytes, Stopwatc
317320
$"Speed: {FormatBytes((long)speed)}/s ETA: {eta:hh\\:mm\\:ss}");
318321

319322
var (leftAfter, topAfter) = Console.GetCursorPosition();
320-
int lengthDifference = leftBefore - leftAfter + (topBefore - topAfter) * Console.WindowWidth;
323+
int lengthDifference = leftBefore - leftAfter + ((topBefore - topAfter) * Console.WindowWidth);
321324
while (lengthDifference > 0)
322325
{
323326
Console.Write(' ');
@@ -345,7 +348,10 @@ private static void ShowFinalProgress(long totalBytesRead, Stopwatch totalStopwa
345348

346349
private static string FormatBytes(long bytes)
347350
{
348-
if (bytes == 0) return "0 Bytes";
351+
if (bytes == 0)
352+
{
353+
return "0 Bytes";
354+
}
349355

350356
const int scale = 1024;
351357
string[] orders = ["GB", "MB", "KB", "Bytes"];
@@ -354,14 +360,17 @@ private static string FormatBytes(long bytes)
354360
foreach (var order in orders)
355361
{
356362
if (bytes >= max)
363+
{
357364
return $"{decimal.Divide(bytes, max):##.##} {order}";
365+
}
366+
358367
max /= scale;
359368
}
360369

361370
return "0 Bytes";
362371
}
363372

364-
private string ResolvePath(string? settingsModelsPath) =>
373+
private static string ResolvePath(string? settingsModelsPath) =>
365374
settingsModelsPath
366375
?? Environment.GetEnvironmentVariable("MaIN_ModelsPath")
367376
?? throw new ModelsPathNotFoundException();

src/MaIN.Domain/Entities/Chat.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ public class Chat
99
{
1010
public string Id { get; init; } = string.Empty;
1111
public required string Name { get; init; }
12-
public required string ModelId { get; set; } // TODO: make set private and settable by the ModelInstance setter
12+
public required string ModelId { get; set; }
13+
private AIModel? _modelInstance;
1314
public AIModel? ModelInstance
1415
{
15-
get => _modelInstance ?? ModelRegistry.GetById(ModelId);
16-
set => _modelInstance = value;
16+
get => _modelInstance ??= ModelRegistry.GetById(ModelId);
17+
set => (_modelInstance, ModelId) = (value, value?.Id ?? ModelId);
1718
}
1819
public List<Message> Messages { get; set; } = [];
1920
public ChatType Type { get; set; } = ChatType.Conversation;
@@ -29,6 +30,4 @@ public AIModel? ModelInstance
2930

3031
public bool Interactive = false;
3132
public bool Translate = false;
32-
33-
private AIModel? _modelInstance;
3433
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Net;
2+
3+
namespace MaIN.Domain.Exceptions.Models;
4+
5+
public class MissingModelInstanceException()
6+
: MaINCustomException("Model instance cannot be null.")
7+
{
8+
public override string PublicErrorMessage => "Model instance cannot be null.";
9+
public override HttpStatusCode HttpStatusCode => HttpStatusCode.BadRequest;
10+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
private string? _incomingMessage = null;
193193
private string? _incomingReasoning = null;
194194
private readonly string? _displayName = Utils.Model;
195-
private IChatMessageBuilder? ctx;
195+
private IChatMessageBuilder? ctxBuilder;
196196
private Chat Chat { get; } = new() { Name = "MaIN Infer", ModelId = Utils.Model! };
197197
private List<MessageExt> Messages { get; set; } = new();
198198
private ElementReference? _bottomElement;

0 commit comments

Comments
 (0)