binding.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // MIT License
  2. // Copyright (c) 2023 go-skynet authors
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. // The above copyright notice and this permission notice shall be included in all
  10. // copies or substantial portions of the Software.
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. // SOFTWARE.
  18. extern "C" {
  19. #include <stdbool.h>
  20. extern unsigned char tokenCallback(void *, char *);
  21. int load_state(void *ctx, char *statefile, char *modes);
  22. int eval(void *params_ptr, void *ctx, char *text);
  23. void save_state(void *ctx, char *dst, char *modes);
  24. void *load_model(const char *fname, int n_ctx, int n_seed, bool memory_f16,
  25. bool mlock, bool embeddings, bool mmap, bool low_vram,
  26. bool vocab_only, int n_gpu, int n_batch, const char *maingpu,
  27. const char *tensorsplit, bool numa);
  28. int get_embeddings(void *params_ptr, void *state_pr, float *res_embeddings);
  29. int get_token_embeddings(void *params_ptr, void *state_pr, int *tokens,
  30. int tokenSize, float *res_embeddings);
  31. void *llama_allocate_params(
  32. const char *prompt, int seed, int threads, int tokens, int top_k,
  33. float top_p, float temp, float repeat_penalty, int repeat_last_n,
  34. bool ignore_eos, bool memory_f16, int n_batch, int n_keep,
  35. const char **antiprompt, int antiprompt_count, float tfs_z, float typical_p,
  36. float frequency_penalty, float presence_penalty, int mirostat,
  37. float mirostat_eta, float mirostat_tau, bool penalize_nl,
  38. const char *logit_bias, bool mlock, bool mmap, const char *maingpu,
  39. const char *tensorsplit);
  40. void llama_free_params(void *params_ptr);
  41. void llama_binding_free_model(void *state);
  42. int llama_predict(void *params_ptr, void *state_pr, char *result, bool debug);
  43. }