File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,25 @@ public LLamaDecodeError(DecodeResult returnCode)
5858 }
5959}
6060
61+ /// <summary>
62+ /// `llama_decode` return a non-zero status code
63+ /// </summary>
64+ public class MissingTemplateError
65+ : RuntimeError
66+ {
67+ /// <inheritdoc />
68+ public MissingTemplateError ( )
69+ : base ( "llama_chat_apply_template failed: template not found" )
70+ {
71+ }
72+
73+ /// <inheritdoc />
74+ public MissingTemplateError ( string message )
75+ : base ( $ "llama_chat_apply_template failed: template not found for '{ message } '")
76+ {
77+ }
78+ }
79+
6180/// <summary>
6281/// `llama_get_logits_ith` returned null, indicating that the index was invalid
6382/// </summary>
Original file line number Diff line number Diff line change 22using System . Collections . Generic ;
33using System . Diagnostics ;
44using System . Text ;
5+ using LLama . Exceptions ;
56using LLama . Native ;
67
78namespace LLama ;
@@ -250,6 +251,19 @@ public ReadOnlySpan<byte> Apply()
250251 {
251252 // Run templater and discover true length
252253 var outputLength = ApplyInternal ( _nativeChatMessages . AsSpan ( 0 , Count ) , output ) ;
254+
255+ // if we have a return code of -1, the template was not found.
256+ if ( outputLength == - 1 )
257+ {
258+ if ( _customTemplate != null )
259+ {
260+ throw new MissingTemplateError ( Encoding . GetString ( _customTemplate ) ) ;
261+ }
262+ else
263+ {
264+ throw new MissingTemplateError ( ) ;
265+ }
266+ }
253267
254268 // If length was too big for output buffer run it again
255269 if ( outputLength > output . Length )
You can’t perform that action at this time.
0 commit comments