@@ -132,7 +132,7 @@ public bool remote
132132 if ( _remote != value )
133133 {
134134 _remote = value ;
135- if ( started ) _ = SetupLLMClient ( ) ;
135+ if ( started ) _ = SetupCaller ( ) ;
136136 }
137137 }
138138 }
@@ -153,7 +153,7 @@ public string APIKey
153153 if ( _APIKey != value )
154154 {
155155 _APIKey = value ;
156- if ( started ) _ = SetupLLMClient ( ) ;
156+ if ( started ) _ = SetupCaller ( ) ;
157157 }
158158 }
159159 }
@@ -167,7 +167,7 @@ public string host
167167 if ( _host != value )
168168 {
169169 _host = value ;
170- if ( started ) _ = SetupLLMClient ( ) ;
170+ if ( started ) _ = SetupCaller ( ) ;
171171 }
172172 }
173173 }
@@ -181,7 +181,7 @@ public int port
181181 if ( _port != value )
182182 {
183183 _port = value ;
184- if ( started ) _ = SetupLLMClient ( ) ;
184+ if ( started ) _ = SetupCaller ( ) ;
185185 }
186186 }
187187 }
@@ -223,7 +223,7 @@ public virtual void Awake()
223223 public virtual async void Start ( )
224224 {
225225 if ( ! enabled ) return ;
226- await SetupLLMClient ( ) ;
226+ await SetupCaller ( ) ;
227227 started = true ;
228228 }
229229
@@ -240,11 +240,11 @@ protected virtual void Reset()
240240 #endregion
241241
242242 #region Initialization
243- protected virtual async Task CheckLLMClient ( bool checkConnection = true )
243+ protected virtual async Task CheckCaller ( bool checkConnection = true )
244244 {
245245 await startSemaphore . WaitAsync ( ) ;
246246 startSemaphore . Release ( ) ;
247- if ( GetCaller ( ) == null ) LLMUnitySetup . LogError ( "LLMClient not initialized" , true ) ;
247+ if ( GetCaller ( ) == null ) LLMUnitySetup . LogError ( "LLM caller not initialized" , true ) ;
248248 if ( remote && checkConnection )
249249 {
250250 for ( int attempt = 0 ; attempt <= numRetries ; attempt ++ )
@@ -258,7 +258,16 @@ protected virtual async Task CheckLLMClient(bool checkConnection = true)
258258 /// <summary>
259259 /// Sets up the underlying LLM client connection (local or remote).
260260 /// </summary>
261- protected virtual async Task SetupLLMClient ( )
261+ protected virtual async Task SetupCaller ( )
262+ {
263+ await SetupCallerObject ( ) ;
264+ await PostSetupCallerObject ( ) ;
265+ }
266+
267+ /// <summary>
268+ /// Sets up the underlying LLM client connection (local or remote).
269+ /// </summary>
270+ protected virtual async Task SetupCallerObject ( )
262271 {
263272 await startSemaphore . WaitAsync ( ) ;
264273
@@ -275,9 +284,6 @@ protected virtual async Task SetupLLMClient()
275284 {
276285 llmClient = new UndreamAI . LlamaLib . LLMClient ( host , port , APIKey , numRetries ) ;
277286 }
278-
279- SetGrammar ( grammar ) ;
280- completionParametersCache = "" ;
281287 }
282288 catch ( Exception ex )
283289 {
@@ -297,6 +303,15 @@ protected virtual async Task SetupLLMClient()
297303 }
298304 }
299305
306+ /// <summary>
307+ /// Initialisation after setting up the LLM client (local or remote).
308+ /// </summary>
309+ protected virtual async Task PostSetupCallerObject ( )
310+ {
311+ SetGrammar ( grammar ) ;
312+ completionParametersCache = "" ;
313+ }
314+
300315 /// <summary>
301316 /// Gets the underlying LLMLocal instance for operations requiring local access.
302317 /// </summary>
@@ -320,7 +335,7 @@ protected virtual async Task SetLLM(LLM llmInstance)
320335 }
321336
322337 _llm = llmInstance ;
323- if ( started ) await SetupLLMClient ( ) ;
338+ if ( started ) await SetupCaller ( ) ;
324339 }
325340
326341 #endregion
@@ -497,7 +512,7 @@ public virtual async Task<List<int>> Tokenize(string query, Callback<List<int>>
497512 {
498513 throw new ArgumentNullException ( nameof ( query ) ) ;
499514 }
500- await CheckLLMClient ( ) ;
515+ await CheckCaller ( ) ;
501516
502517 List < int > tokens = llmClient . Tokenize ( query ) ;
503518 callback ? . Invoke ( tokens ) ;
@@ -516,7 +531,7 @@ public virtual async Task<string> Detokenize(List<int> tokens, Callback<string>
516531 {
517532 throw new ArgumentNullException ( nameof ( tokens ) ) ;
518533 }
519- await CheckLLMClient ( ) ;
534+ await CheckCaller ( ) ;
520535
521536 string text = llmClient . Detokenize ( tokens ) ;
522537 callback ? . Invoke ( text ) ;
@@ -535,7 +550,7 @@ public virtual async Task<List<float>> Embeddings(string query, Callback<List<fl
535550 {
536551 throw new ArgumentNullException ( nameof ( query ) ) ;
537552 }
538- await CheckLLMClient ( ) ;
553+ await CheckCaller ( ) ;
539554
540555 List < float > embeddings = llmClient . Embeddings ( query ) ;
541556 callback ? . Invoke ( embeddings ) ;
@@ -553,7 +568,7 @@ public virtual async Task<List<float>> Embeddings(string query, Callback<List<fl
553568 public virtual async Task < string > Completion ( string prompt , LlamaLib . CharArrayCallback callback = null ,
554569 EmptyCallback completionCallback = null , int id_slot = - 1 )
555570 {
556- await CheckLLMClient ( ) ;
571+ await CheckCaller ( ) ;
557572 SetCompletionParameters ( ) ;
558573 string result = await llmClient . CompletionAsync ( prompt , callback , id_slot ) ;
559574 completionCallback ? . Invoke ( ) ;
0 commit comments