sampling_ext.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // TODO: this is a temporary wrapper to allow calling C++ code from CGo
  2. #ifndef LLAMA_SAMPLING_EXT_H
  3. #define LLAMA_SAMPLING_EXT_H
  4. #include "llama.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. struct llama_sampling_cparams {
  9. int32_t top_k;
  10. float top_p;
  11. float tfs_z;
  12. float typical_p;
  13. float temp;
  14. float penalty_repeat;
  15. float penalty_freq;
  16. float penalty_present;
  17. int32_t mirostat;
  18. float mirostat_tau;
  19. float mirostat_eta;
  20. bool penalize_nl;
  21. uint32_t seed;
  22. char* grammar;
  23. };
  24. struct llama_sampling_context* llama_sampling_cinit(struct llama_sampling_cparams *params);
  25. void llama_sampling_cfree(struct llama_sampling_context * ctx);
  26. void llama_sampling_creset(struct llama_sampling_context * ctx);
  27. llama_token llama_sampling_csample(
  28. struct llama_sampling_context * ctx_sampling,
  29. struct llama_context * ctx_main,
  30. struct llama_context * ctx_cfg,
  31. int idx);
  32. void llama_sampling_caccept(
  33. struct llama_sampling_context * ctx_sampling,
  34. struct llama_context * ctx_main,
  35. llama_token id,
  36. bool apply_grammar);
  37. #ifdef __cplusplus
  38. }
  39. #endif
  40. #endif // LLAMA_SAMPLING_EXT_H