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 2.0 kB

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