You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

NativeApi.Grammar.cs 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace LLama.Native
  4. {
  5. using llama_token = Int32;
  6. public unsafe partial class NativeApi
  7. {
  8. /// <summary>
  9. /// Create a new grammar from the given set of grammar rules
  10. /// </summary>
  11. /// <param name="rules"></param>
  12. /// <param name="n_rules"></param>
  13. /// <param name="start_rule_index"></param>
  14. /// <returns></returns>
  15. [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
  16. public static extern IntPtr llama_grammar_init(LLamaGrammarElement** rules, ulong n_rules, ulong start_rule_index);
  17. /// <summary>
  18. /// Free all memory from the given SafeLLamaGrammarHandle
  19. /// </summary>
  20. /// <param name="grammar"></param>
  21. [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
  22. public static extern void llama_grammar_free(IntPtr grammar);
  23. /// <summary>
  24. /// Apply constraints from grammar
  25. /// </summary>
  26. /// <param name="ctx"></param>
  27. /// <param name="candidates"></param>
  28. /// <param name="grammar"></param>
  29. [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
  30. public static extern void llama_sample_grammar(SafeLLamaContextHandle ctx, ref LLamaTokenDataArrayNative candidates, SafeLLamaGrammarHandle grammar);
  31. /// <summary>
  32. /// Accepts the sampled token into the grammar
  33. /// </summary>
  34. /// <param name="ctx"></param>
  35. /// <param name="grammar"></param>
  36. /// <param name="token"></param>
  37. [DllImport(libraryName, CallingConvention = CallingConvention.Cdecl)]
  38. public static extern void llama_grammar_accept_token(SafeLLamaContextHandle ctx, SafeLLamaGrammarHandle grammar, llama_token token);
  39. }
  40. }