binding.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include <stdbool.h>
  22. extern unsigned char tokenCallback(void *, char *);
  23. int load_state(void *ctx, char *statefile, char *modes);
  24. int eval(void *params_ptr, void *ctx, char *text);
  25. void save_state(void *ctx, char *dst, char *modes);
  26. void *load_model(const char *fname, int n_ctx, int n_seed, bool memory_f16,
  27. bool mlock, bool embeddings, bool mmap, bool low_vram,
  28. bool vocab_only, int n_gpu, int n_batch, const char *maingpu,
  29. const char *tensorsplit, bool numa);
  30. int get_embeddings(void *params_ptr, void *state_pr, float *res_embeddings);
  31. int get_token_embeddings(void *params_ptr, void *state_pr, int *tokens,
  32. int tokenSize, float *res_embeddings);
  33. void *llama_allocate_params(
  34. const char *prompt, int seed, int threads, int tokens, int top_k,
  35. float top_p, float temp, float repeat_penalty, int repeat_last_n,
  36. bool ignore_eos, bool memory_f16, int n_batch, int n_keep,
  37. const char **antiprompt, int antiprompt_count, float tfs_z, float typical_p,
  38. float frequency_penalty, float presence_penalty, int mirostat,
  39. float mirostat_eta, float mirostat_tau, bool penalize_nl,
  40. const char *logit_bias, bool mlock, bool mmap, const char *maingpu,
  41. const char *tensorsplit);
  42. void llama_free_params(void *params_ptr);
  43. void llama_binding_free_model(void *state);
  44. int llama_predict(void *params_ptr, void *state_pr, char *result, bool debug);
  45. #ifdef __cplusplus
  46. }
  47. #endif