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)
58
58
}
59
59
}
60
60
61
+ /// <summary>
62
+ /// `llama_decode` return a non-zero status code
63
+ /// </summary>
64
+ public class MissingTemplateException
65
+ : RuntimeError
66
+ {
67
+ /// <inheritdoc />
68
+ public MissingTemplateException ( )
69
+ : base ( "llama_chat_apply_template failed: template not found" )
70
+ {
71
+ }
72
+
73
+ /// <inheritdoc />
74
+ public MissingTemplateException ( string message )
75
+ : base ( $ "llama_chat_apply_template failed: template not found for '{ message } '")
76
+ {
77
+ }
78
+ }
79
+
61
80
/// <summary>
62
81
/// `llama_get_logits_ith` returned null, indicating that the index was invalid
63
82
/// </summary>
Original file line number Diff line number Diff line change 2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
4
using System . Text ;
5
+ using LLama . Exceptions ;
5
6
using LLama . Native ;
6
7
7
8
namespace LLama ;
@@ -250,6 +251,19 @@ public ReadOnlySpan<byte> Apply()
250
251
{
251
252
// Run templater and discover true length
252
253
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 MissingTemplateException ( Encoding . GetString ( _customTemplate ) ) ;
261
+ }
262
+ else
263
+ {
264
+ throw new MissingTemplateException ( ) ;
265
+ }
266
+ }
253
267
254
268
// If length was too big for output buffer run it again
255
269
if ( outputLength > output . Length )
You can’t perform that action at this time.
0 commit comments