sampling_ext.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // TODO: this is a temporary wrapper to allow calling C++ code from CGo
  2. #ifndef SAMPLING_EXT_H
  3. #define SAMPLING_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 common_sampler;
  11. struct common_sampler_cparams {
  12. int32_t top_k;
  13. float top_p;
  14. float min_p;
  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. uint32_t seed;
  25. char *grammar;
  26. };
  27. struct common_sampler *common_sampler_cinit(const struct llama_model *model, struct common_sampler_cparams *params);
  28. void common_sampler_cfree(struct common_sampler *sampler);
  29. void common_sampler_creset(struct common_sampler *sampler);
  30. void common_sampler_caccept(struct common_sampler *sampler, llama_token id, bool apply_grammar);
  31. llama_token common_sampler_csample(struct common_sampler *sampler, struct llama_context *ctx, int idx);
  32. int schema_to_grammar(const char *json_schema, char *grammar, size_t max_len);
  33. struct llama_vocab * llama_load_vocab_from_file(const char * fname);
  34. void llama_free_vocab(struct llama_vocab * vocab);
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #endif // SAMPLING_EXT_H