11using FuzzySharp ;
2+ using MaIN . Core . E2ETests . Helpers ;
23using MaIN . Core . Hub ;
3- using MaIN . Core . IntegrationTests . Helpers ;
44using MaIN . Domain . Entities ;
55using MaIN . Domain . Models ;
66using MaIN . Domain . Models . Abstract ;
77
8- namespace MaIN . Core . IntegrationTests ;
8+ namespace MaIN . Core . E2ETests ;
99
10+ [ Collection ( "E2ETests" ) ]
1011public class ChatTests : IntegrationTestBase
1112{
1213 public ChatTests ( ) : base ( )
@@ -16,7 +17,7 @@ public ChatTests() : base()
1617 [ Fact ]
1718 public async Task Should_AnswerQuestion_BasicChat ( )
1819 {
19- var context = AIHub . Chat ( ) . WithModel ( Models . Local . Gemma2_2b ) ;
20+ var context = AIHub . Chat ( ) . WithModel ( Models . Local . Qwen2_5_0_5b ) ;
2021
2122 var result = await context
2223 . WithMessage ( "Where the hedgehog goes at night?" )
@@ -28,28 +29,38 @@ public async Task Should_AnswerQuestion_BasicChat()
2829 }
2930
3031 [ Fact ]
31- public async Task Should_AnswerDifferences_BetweenDocuments_ChatWithFiles ( )
32+ public async Task Should_AnswerFileSubject_ChatWithFiles ( )
3233 {
33- List < string > files = [ "./Files/Nicolaus_Copernicus.pdf" , "./Files/Galileo_Galilei.pdf" ] ;
34+ List < string > files = [ "./Files/Nicolaus_Copernicus.pdf" ] ;
3435
3536 var result = await AIHub . Chat ( )
36- . WithModel ( Models . Local . Gemma2_2b )
37- . WithMessage ( "You have 2 documents in memory. Whats the difference of work between Galileo and Copernicus?. Give answer based on the documents." )
37+ . WithModel ( Models . Local . Qwen2_5_0_5b )
38+ . WithMessage ( "Who is described in the file? Reply with ONLY their full name. No explanation, no punctuation. Example: Isaak Newton" )
39+ . WithMemoryParams ( new MemoryParams { AnswerTokens = 10 } )
3840 . WithFiles ( files )
3941 . CompleteAsync ( ) ;
4042
4143 Assert . True ( result . Done ) ;
4244 Assert . NotNull ( result . Message ) ;
4345 Assert . NotEmpty ( result . Message . Content ) ;
46+ var ratio = Fuzz . PartialRatio ( "nicolaus copernicus" , result . Message . Content . ToLowerInvariant ( ) ) ;
47+ Assert . True ( ratio > 50 ,
48+ $ """
49+ Fuzzy match failed!
50+ Expected > 50, but got { ratio } .
51+ Expected: 'nicolaus copernicus'
52+ Actual: '{ result . Message . Content } '
53+ """ ) ;
4454 }
4555
4656 [ Fact ]
4757 public async Task Should_AnswerQuestion_FromExistingChat ( )
4858 {
4959 var result = AIHub . Chat ( )
50- . WithModel ( Models . Local . Gemma2_2b ) ;
60+ . WithModel ( Models . Local . Qwen2_5_0_5b ) ;
5161
5262 await result . WithMessage ( "What do you think about math theories?" )
63+ . WithMemoryParams ( new MemoryParams { AnswerTokens = 10 } )
5364 . CompleteAsync ( ) ;
5465
5566 await result . WithMessage ( "And about physics?" )
@@ -62,29 +73,53 @@ await result.WithMessage("And about physics?")
6273 }
6374
6475 [ Fact ]
65- public async Task Should_AnswerGameFromImage_ChatWithVision ( )
76+ public async Task Should_AnswerGameFromImage_ChatWithImagesWithText ( )
6677 {
6778 List < string > images = [ "./Files/gamex.jpg" ] ;
79+ var expectedAnswer = "call of duty" ;
6880
6981 var result = await AIHub . Chat ( )
7082 . WithModel ( Models . Local . Llama3_2_3b )
71- . WithMessage ( "What is the title of the game? Answer only this question." )
72- . WithMemoryParams ( new MemoryParams
73- {
74- AnswerTokens = 1000
75- } )
83+ . WithMessage ( "What is the title of the game? Answer in 3 words." )
84+ . WithMemoryParams ( new MemoryParams { AnswerTokens = 10 } )
85+ . WithFiles ( images )
86+ . CompleteAsync ( ) ;
87+
88+ Assert . True ( result . Done ) ;
89+ Assert . NotNull ( result . Message ) ;
90+ Assert . NotEmpty ( result . Message . Content ) ;
91+ var ratio = Fuzz . PartialRatio ( expectedAnswer , result . Message . Content . ToLowerInvariant ( ) ) ;
92+ Assert . True ( ratio > 50 ,
93+ $ """
94+ Fuzzy match failed!
95+ Expected > 50, but got { ratio } .
96+ Expexted: '{ expectedAnswer } '
97+ Actual: '{ result . Message . Content } '
98+ """ ) ;
99+ }
100+
101+ [ Fact ]
102+ public async Task Should_AnswerAppleFromImage_ChatWithImagesWithVision ( )
103+ {
104+ List < string > images = [ "./Files/apple.jpg" ] ;
105+ var expectedAnswer = "apple" ;
106+
107+ var result = await AIHub . Chat ( )
108+ . WithModel ( Models . Local . Gemma3_4b )
109+ . WithMessage ( "What is this fruit? Answer in one word." )
110+ . WithMemoryParams ( new MemoryParams { AnswerTokens = 10 } )
76111 . WithFiles ( images )
77112 . CompleteAsync ( ) ;
78113
79114 Assert . True ( result . Done ) ;
80115 Assert . NotNull ( result . Message ) ;
81116 Assert . NotEmpty ( result . Message . Content ) ;
82- var ratio = Fuzz . PartialRatio ( "call of duty" , result . Message . Content . ToLowerInvariant ( ) ) ;
117+ var ratio = Fuzz . PartialRatio ( expectedAnswer , result . Message . Content . ToLowerInvariant ( ) ) ;
83118 Assert . True ( ratio > 50 ,
84119 $ """
85120 Fuzzy match failed!
86121 Expected > 50, but got { ratio } .
87- Expexted: 'call of duty '
122+ Expexted: '{ expectedAnswer } '
88123 Actual: '{ result . Message . Content } '
89124 """ ) ;
90125 }
@@ -113,9 +148,9 @@ public async Task Should_GenerateImage_BasedOnPrompt()
113148 }
114149
115150 [ Fact ]
116- public async Task Should_AnswerDifferences_BetweenDocuments_ChatWithFiles_UsingStreams ( )
151+ public async Task Should_AnswerFileSubject_ChatWithFiles_UsingStreams ( )
117152 {
118- List < string > files = [ "./Files/Nicolaus_Copernicus.pdf" , "./Files/Galileo_Galilei.pdf" ] ;
153+ List < string > files = [ "./Files/Nicolaus_Copernicus.pdf" ] ;
119154
120155 var fileStreams = new List < FileStream > ( ) ;
121156
@@ -135,14 +170,25 @@ public async Task Should_AnswerDifferences_BetweenDocuments_ChatWithFiles_UsingS
135170 fileStreams . Add ( fs ) ;
136171 }
137172
173+ var expectedAnswer = "nicolaus copernicus" ;
174+
138175 var result = await AIHub . Chat ( )
139- . WithModel ( Models . Local . Gemma2_2b )
140- . WithMessage ( "You have 2 documents in memory. Whats the difference of work between Galileo and Copernicus?. Give answer based on the documents." )
176+ . WithModel ( Models . Local . Qwen2_5_0_5b )
177+ . WithMessage ( "Who is described in the file? Reply with ONLY their full name. No explanation, no punctuation. Example: Isaak Newton" )
178+ . WithMemoryParams ( new MemoryParams { AnswerTokens = 10 } )
141179 . WithFiles ( fileStreams )
142180 . CompleteAsync ( ) ;
143181
144182 Assert . True ( result . Done ) ;
145183 Assert . NotNull ( result . Message ) ;
146184 Assert . NotEmpty ( result . Message . Content ) ;
185+ var ratio = Fuzz . PartialRatio ( expectedAnswer , result . Message . Content . ToLowerInvariant ( ) ) ;
186+ Assert . True ( ratio > 50 ,
187+ $ """
188+ Fuzzy match failed!
189+ Expected > 50, but got { ratio } .
190+ Expected: '{ expectedAnswer } '
191+ Actual: '{ result . Message . Content } '
192+ """ ) ;
147193 }
148194}
0 commit comments