sampling_ext.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. };
  23. struct llama_sampling_context* llama_sampling_cinit(struct llama_sampling_cparams *params);
  24. void llama_sampling_cfree(struct llama_sampling_context * ctx);
  25. void llama_sampling_creset(struct llama_sampling_context * ctx);
  26. llama_token llama_sampling_csample(
  27. struct llama_sampling_context * ctx_sampling,
  28. struct llama_context * ctx_main,
  29. struct llama_context * ctx_cfg,
  30. int idx);
  31. void llama_sampling_caccept(
  32. struct llama_sampling_context * ctx_sampling,
  33. struct llama_context * ctx_main,
  34. llama_token id,
  35. bool apply_grammar);
  36. #ifdef __cplusplus
  37. }
  38. #endif
  39. #endif // LLAMA_SAMPLING_EXT_H