sampling_ext.h 1.2 KB

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