-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathChatTests.cs
More file actions
131 lines (103 loc) · 4.13 KB
/
ChatTests.cs
File metadata and controls
131 lines (103 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using MaIN.Core.Hub;
using MaIN.Domain.Entities;
namespace MaIN.Core.IntegrationTests;
public class ChatTests : IntegrationTestBase
{
public ChatTests() : base()
{
}
[Fact]
public async Task Should_AnswerQuestion_BasicChat()
{
var context = AIHub.Chat().WithModel("gemma2:2b");
var result = await context
.WithMessage("Where the hedgehog goes at night?")
.CompleteAsync(interactive: true);
Assert.True(result.Done);
Assert.NotNull(result.Message);
Assert.NotEmpty(result.Message.Content);
}
[Fact]
public async Task Should_AnswerDifferences_BetweenDocuments_ChatWithFiles()
{
List<string> files = ["./Files/Nicolaus_Copernicus.pdf", "./Files/Galileo_Galilei.pdf"];
var result = await AIHub.Chat()
.WithModel("gemma2:2b")
.WithMessage("You have 2 documents in memory. Whats the difference of work between Galileo and Copernicus?. Give answer based on the documents.")
.WithFiles(files)
.CompleteAsync();
Assert.True(result.Done);
Assert.NotNull(result.Message);
Assert.NotEmpty(result.Message.Content);
}
[Fact]
public async Task Should_AnswerQuestion_FromExistingChat()
{
var result = AIHub.Chat()
.WithModel("qwen2.5:0.5b");
await result.WithMessage("What do you think about math theories?")
.CompleteAsync();
await result.WithMessage("And about physics?")
.CompleteAsync();
var chatNewContext = await AIHub.Chat().FromExisting(result.GetChatId());
var messages = chatNewContext.GetChatHistory();
Assert.Equal(4, messages.Count);
}
[Fact]
public async Task Should_AnswerGameFromImage_ChatWithVision()
{
List<string> images = ["./Files/gamex.jpg"];
var result = await AIHub.Chat()
.WithModel("llama3.2:3b")
.WithMemoryParams(new MemoryParams
{
AnswerTokens = 1000
})
.WithMessage("What is the title of game?")
.WithFiles(images)
.CompleteAsync();
Assert.True(result.Done);
Assert.NotNull(result.Message);
Assert.NotEmpty(result.Message.Content);
Assert.Contains("call of duty", result.Message.Content.ToLower());
}
[Fact(Skip = "Require powerful GPU")]
public async Task Should_GenerateImage_BasedOnPrompt()
{
Assert.True(PingHost("127.0.0.1", 5003, 5), "Please make sure ImageGen service is running on port 5003");
const string extension = "png";
var result = await AIHub.Chat()
.EnableVisual()
.WithMessage("Generate cat in Rome. Sightseeing, colloseum, ancient builidngs, Italy.")
.CompleteAsync();
if (string.IsNullOrWhiteSpace(extension) || extension.Contains("."))
throw new ArgumentException("Invalid file extension");
Assert.True(result.Done);
Assert.NotNull(result.Message.Image);
}
[Fact]
public async Task Should_AnswerDifferences_BetweenDocuments_ChatWithFiles_UsingStreams()
{
List<string> files = ["./Files/Nicolaus_Copernicus.pdf", "./Files/Galileo_Galilei.pdf"];
var fileStreams = new List<FileStream>();
foreach (var path in files)
{
if (!File.Exists(path))
continue;
var fs = new FileStream(
path,
FileMode.Open,
FileAccess.Read,
FileShare.Read);
fileStreams.Add(fs);
}
var result = await AIHub.Chat()
.WithModel("gemma2:2b")
.WithMessage("You have 2 documents in memory. Whats the difference of work between Galileo and Copernicus?. Give answer based on the documents.")
.WithFiles(fileStreams)
.CompleteAsync();
Assert.True(result.Done);
Assert.NotNull(result.Message);
Assert.NotEmpty(result.Message.Content);
}
}