sampling_ext.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. {
  8. #endif
  9. struct llama_sampling_cparams
  10. {
  11. int32_t top_k;
  12. float top_p;
  13. float min_p;
  14. float tfs_z;
  15. float typical_p;
  16. float temp;
  17. int32_t penalty_last_n;
  18. float penalty_repeat;
  19. float penalty_freq;
  20. float penalty_present;
  21. int32_t mirostat;
  22. float mirostat_tau;
  23. float mirostat_eta;
  24. bool penalize_nl;
  25. uint32_t seed;
  26. char *grammar;
  27. };
  28. struct llama_sampling_context *llama_sampling_cinit(struct llama_sampling_cparams *params);
  29. void llama_sampling_cfree(struct llama_sampling_context *ctx);
  30. void llama_sampling_creset(struct llama_sampling_context *ctx);
  31. llama_token llama_sampling_csample(
  32. struct llama_sampling_context *ctx_sampling,
  33. struct llama_context *ctx_main,
  34. struct llama_context *ctx_cfg,
  35. int idx);
  36. void llama_sampling_caccept(
  37. struct llama_sampling_context *ctx_sampling,
  38. struct llama_context *ctx_main,
  39. llama_token id,
  40. bool apply_grammar);
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. #endif // LLAMA_SAMPLING_EXT_H