Skip to content

Commit 6ed0e1b

Browse files
Merge pull request #60 from wisedev-code/feat/vl-integration
Feat/vl integration
2 parents b06232f + e3e5715 commit 6ed0e1b

19 files changed

Lines changed: 114 additions & 64 deletions

File tree

Examples/Examples/Agents/AgentsWithRedirectImageExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ Generate image based on given prompt
5151
}]
5252
});
5353

54-
ImagePreview.ShowImage(result.Message.Images);
54+
ImagePreview.ShowImage(result.Message.Image);
5555
}
5656
}

Examples/Examples/Chat/ChatWithImageGenExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public async Task Start()
1414
.WithMessage("Generate cyberpunk godzilla cat warrior")
1515
.CompleteAsync();
1616

17-
ImagePreview.ShowImage(result.Message.Images);
17+
ImagePreview.ShowImage(result.Message.Image);
1818
}
1919
}

Examples/Examples/Chat/ChatWithImageGenGeminiExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public async Task Start()
1515
.WithMessage("Generate hamster as a astronaut on the moon")
1616
.CompleteAsync();
1717

18-
ImagePreview.ShowImage(result.Message.Images);
18+
ImagePreview.ShowImage(result.Message.Image);
1919
}
2020
}

Examples/Examples/Chat/ChatWithImageGenOpenAiExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public async Task Start()
1515
.WithMessage("Generate rock style cow playing guitar")
1616
.CompleteAsync();
1717

18-
ImagePreview.ShowImage(result.Message.Images);
18+
ImagePreview.ShowImage(result.Message.Image);
1919
}
2020
}
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
using System.Reflection;
21
using MaIN.Core.Hub;
32

43
namespace Examples;
54

65
public class ChatWithVisionExample : IExample
76
{
8-
/// <summary>
9-
/// Vision via Multimodal models as Llava is not supported yet
10-
/// </summary>
117
public async Task Start()
128
{
13-
Console.WriteLine("ChatExample with files is running!");
9+
//https://huggingface.co/cjpais/llava-1.6-mistral-7b-gguf - Tried with this model
10+
Console.WriteLine("ChatExample with vision model is running!");
1411

15-
List<string> images = [Path.Combine(AppContext.BaseDirectory, "Files", "gamex.jpg")];
12+
var image = await File.ReadAllBytesAsync(
13+
Path.Combine(AppContext.BaseDirectory, "Files", "gamex.jpg"));
1614

17-
var result = await AIHub.Chat()
18-
.WithModel("llama3.2:3b")
19-
.WithMessage("What is the title of game?")
20-
.WithFiles(images)
21-
.CompleteAsync();
22-
23-
Console.WriteLine(result.Message.Content);
15+
await AIHub.Chat()
16+
.WithCustomModel("Llava1.6-Mistral",
17+
path: "<path_to_model>.gguf",
18+
mmProject: "<path_to_mmproj>.gguf")
19+
.WithMessage("What can you see on the image?", image)
20+
.CompleteAsync(interactive: true);
2421
}
2522
}

MaIN.Core.IntegrationTests/ChatTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public async Task Should_GenerateImage_BasedOnPrompt()
9898
throw new ArgumentException("Invalid file extension");
9999

100100
Assert.True(result.Done);
101-
Assert.NotNull(result.Message.Images);
101+
Assert.NotNull(result.Message.Image);
102102
}
103103

104104
[Fact]

Releases/0.2.5.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.2.5 release
2+
3+
- Integrate with vision llava 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.2.4</version>
5+
<version>0.2.5</version>
66
<authors>Wisedev</authors>
77
<owners>Wisedev</owners>
88
<icon>favicon.png</icon>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ public AgentContext WithMemoryParams(MemoryParams memoryParams)
114114
return this;
115115
}
116116

117-
public AgentContext WithCustomModel(string model, string path)
117+
public AgentContext WithCustomModel(string model, string path, string? mmProject = null)
118118
{
119-
KnownModels.AddModel(model, path);
119+
KnownModels.AddModel(model, path, mmProject);
120120
_agent.Model = model;
121121
return this;
122122
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public ChatContext WithMemoryParams(MemoryParams memoryParams)
5454
return this;
5555
}
5656

57-
public ChatContext WithCustomModel(string model, string path)
57+
public ChatContext WithCustomModel(string model, string path, string? mmProject = null)
5858
{
59-
KnownModels.AddModel(model, path);
59+
KnownModels.AddModel(model, path, mmProject);
6060
_chat.Model = model;
6161
return this;
6262
}
@@ -79,6 +79,21 @@ public ChatContext WithMessage(string content)
7979
_chat.Messages.Add(message);
8080
return this;
8181
}
82+
83+
84+
public ChatContext WithMessage(string content, byte[] image)
85+
{
86+
var message = new Message
87+
{
88+
Role = "User",
89+
Content = content,
90+
Time = DateTime.Now,
91+
Image = image
92+
};
93+
94+
_chat.Messages.Add(message);
95+
return this;
96+
}
8297

8398
public ChatContext WithSystemPrompt(string systemPrompt)
8499
{

0 commit comments

Comments
 (0)