7
7
using System . Collections ;
8
8
using System . IO ;
9
9
using System . Linq ;
10
+ using System . Threading ;
10
11
using UnityEngine . TestTools ;
11
12
using UnityEditor ;
12
13
using UnityEditor . TestTools . TestRunner . Api ;
@@ -116,7 +117,9 @@ public class TestLLM
116
117
protected string reply2 ;
117
118
protected int tokens1 ;
118
119
protected int tokens2 ;
120
+ protected int port ;
119
121
122
+ static readonly object _lock = new object ( ) ;
120
123
121
124
public TestLLM ( )
122
125
{
@@ -126,6 +129,8 @@ public TestLLM()
126
129
127
130
public virtual async Task Init ( )
128
131
{
132
+ Monitor . Enter ( _lock ) ;
133
+ port = new System . Random ( ) . Next ( 10000 , 20000 ) ;
129
134
SetParameters ( ) ;
130
135
await DownloadModels ( ) ;
131
136
gameObject = new GameObject ( ) ;
@@ -226,6 +231,7 @@ public virtual LLM CreateLLM()
226
231
LLM llm = gameObject . AddComponent < LLM > ( ) ;
227
232
llm . SetModel ( modelNameLLManager ) ;
228
233
llm . parallelPrompts = 1 ;
234
+ llm . port = port ;
229
235
return llm ;
230
236
}
231
237
@@ -240,6 +246,7 @@ public virtual LLMCharacter CreateLLMCharacter()
240
246
llmCharacter . seed = 0 ;
241
247
llmCharacter . stream = false ;
242
248
llmCharacter . numPredict = 20 ;
249
+ llmCharacter . port = port ;
243
250
return llmCharacter ;
244
251
}
245
252
@@ -336,7 +343,13 @@ public void TestEmbeddings(List<float> embeddings)
336
343
Assert . That ( embeddings . Count == 896 ) ;
337
344
}
338
345
339
- public virtual void OnDestroy ( ) { }
346
+ public virtual void OnDestroy ( )
347
+ {
348
+ if ( Monitor . IsEntered ( _lock ) )
349
+ {
350
+ Monitor . Exit ( _lock ) ;
351
+ }
352
+ }
340
353
}
341
354
342
355
public class TestLLM_LLMManager_Load : TestLLM
@@ -371,6 +384,7 @@ public override LLM CreateLLM()
371
384
372
385
public override void OnDestroy ( )
373
386
{
387
+ base . OnDestroy ( ) ;
374
388
if ( ! File . Exists ( loadPath ) ) File . Delete ( loadPath ) ;
375
389
}
376
390
}
0 commit comments