@@ -246,9 +246,9 @@ public virtual async Task Tests()
246
246
247
247
public void TestInitParameters ( int nkeep , int chats )
248
248
{
249
- Assert . That ( llmCharacter . nKeep == nkeep ) ;
249
+ Assert . AreEqual ( llmCharacter . nKeep , nkeep ) ;
250
250
Assert . That ( ChatTemplate . GetTemplate ( llm . chatTemplate ) . GetStop ( llmCharacter . playerName , llmCharacter . AIName ) . Length > 0 ) ;
251
- Assert . That ( llmCharacter . chat . Count == chats ) ;
251
+ Assert . AreEqual ( llmCharacter . chat . Count , chats ) ;
252
252
}
253
253
254
254
public void TestTokens ( List < int > tokens )
@@ -410,7 +410,7 @@ public override async Task Tests()
410
410
public class TestLLM_Double : TestLLM
411
411
{
412
412
LLM llm1 ;
413
- LLMCharacter lLMCharacter1 ;
413
+ LLMCharacter llmCharacter1 ;
414
414
415
415
public override async Task Init ( )
416
416
{
@@ -421,8 +421,51 @@ public override async Task Init()
421
421
llm = CreateLLM ( ) ;
422
422
llmCharacter = CreateLLMCharacter ( ) ;
423
423
llm1 = CreateLLM ( ) ;
424
- lLMCharacter1 = CreateLLMCharacter ( ) ;
424
+ llmCharacter1 = CreateLLMCharacter ( ) ;
425
425
gameObject . SetActive ( true ) ;
426
426
}
427
427
}
428
+
429
+ public class TestLLMCharacter_Save : TestLLM
430
+ {
431
+ string saveName = "TestLLMCharacter_Save" ;
432
+
433
+ public override LLMCharacter CreateLLMCharacter ( )
434
+ {
435
+ LLMCharacter llmCharacter = base . CreateLLMCharacter ( ) ;
436
+ llmCharacter . save = saveName ;
437
+ llmCharacter . saveCache = true ;
438
+ return llmCharacter ;
439
+ }
440
+
441
+ public override async Task Tests ( )
442
+ {
443
+ await base . Tests ( ) ;
444
+ TestSave ( ) ;
445
+ }
446
+
447
+ public void TestSave ( )
448
+ {
449
+ string jsonPath = llmCharacter . GetJsonSavePath ( saveName ) ;
450
+ string cachePath = llmCharacter . GetCacheSavePath ( saveName ) ;
451
+ Assert . That ( File . Exists ( jsonPath ) ) ;
452
+ Assert . That ( File . Exists ( cachePath ) ) ;
453
+ string json = File . ReadAllText ( jsonPath ) ;
454
+ File . Delete ( jsonPath ) ;
455
+ File . Delete ( cachePath ) ;
456
+
457
+ List < ChatMessage > chatHistory = JsonUtility . FromJson < ChatListWrapper > ( json ) . chat ;
458
+ Assert . AreEqual ( chatHistory . Count , 2 ) ;
459
+ Assert . AreEqual ( chatHistory [ 0 ] . role , llmCharacter . playerName ) ;
460
+ Assert . AreEqual ( chatHistory [ 0 ] . content , "hi" ) ;
461
+ Assert . AreEqual ( chatHistory [ 1 ] . role , llmCharacter . AIName ) ;
462
+
463
+ Assert . AreEqual ( llmCharacter . chat . Count , chatHistory . Count + 1 ) ;
464
+ for ( int i = 0 ; i < chatHistory . Count ; i ++ )
465
+ {
466
+ Assert . AreEqual ( chatHistory [ i ] . role , llmCharacter . chat [ i + 1 ] . role ) ;
467
+ Assert . AreEqual ( chatHistory [ i ] . content , llmCharacter . chat [ i + 1 ] . content ) ;
468
+ }
469
+ }
470
+ }
428
471
}
0 commit comments