sampling_ext.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // TODO: this is a temporary wrapper to allow calling C++ code from CGo
  2. #ifndef GPT_SAMPLER_EXT_H
  3. #define GPT_SAMPLER_EXT_H
  4. #ifdef __cplusplus
  5. extern "C"
  6. {
  7. #endif
  8. // Forward declaration to avoid include of "sampling.h" which has c++
  9. // includes
  10. struct gpt_sampler;
  11. struct gpt_sampler_cparams
  12. {
  13. int32_t top_k;
  14. float top_p;
  15. float min_p;
  16. float tfs_z;
  17. float typical_p;
  18. float temp;
  19. int32_t penalty_last_n;
  20. float penalty_repeat;
  21. float penalty_freq;
  22. float penalty_present;
  23. int32_t mirostat;
  24. float mirostat_tau;
  25. float mirostat_eta;
  26. bool penalize_nl;
  27. uint32_t seed;
  28. char *grammar;
  29. };
  30. struct gpt_sampler *gpt_sampler_cinit(
  31. const struct llama_model *model,
  32. struct gpt_sampler_cparams *params);
  33. void gpt_sampler_cfree(struct gpt_sampler *sampler);
  34. void gpt_sampler_creset(struct gpt_sampler *sampler);
  35. llama_token gpt_sampler_csample(
  36. struct gpt_sampler *sampler,
  37. struct llama_context *ctx_main,
  38. int idx);
  39. void gpt_sampler_caccept(
  40. struct gpt_sampler *sampler,
  41. llama_token id,
  42. bool apply_grammar);
  43. int schema_to_grammar(const char *json_schema, char *grammar, size_t max_len);
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #endif // GPT_SAMPLER_EXT_H