binding.h 2.58 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// MIT License

// Copyright (c) 2023 go-skynet authors

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

Jeffrey Morgan's avatar
Jeffrey Morgan committed
23
24
#ifdef __cplusplus

Jeffrey Morgan's avatar
Jeffrey Morgan committed
25
26
extern "C" {

Jeffrey Morgan's avatar
Jeffrey Morgan committed
27
28
#endif

Jeffrey Morgan's avatar
Jeffrey Morgan committed
29
30
31
32
#include <stdbool.h>

extern unsigned char tokenCallback(void *, char *);

Jeffrey Morgan's avatar
Jeffrey Morgan committed
33
34
35
36
37
int load_state(void *ctx, char *statefile, char *modes);

int eval(void *params_ptr, void *ctx, char *text);

void save_state(void *ctx, char *dst, char *modes);
Jeffrey Morgan's avatar
Jeffrey Morgan committed
38
39
40
41
42
43

void *load_model(const char *fname, int n_ctx, int n_seed, bool memory_f16,
                 bool mlock, bool embeddings, bool mmap, bool low_vram,
                 bool vocab_only, int n_gpu, int n_batch, const char *maingpu,
                 const char *tensorsplit, bool numa);

Jeffrey Morgan's avatar
Jeffrey Morgan committed
44
45
46
47
48
int get_embeddings(void *params_ptr, void *state_pr, float *res_embeddings);

int get_token_embeddings(void *params_ptr, void *state_pr, int *tokens,
                         int tokenSize, float *res_embeddings);

Jeffrey Morgan's avatar
Jeffrey Morgan committed
49
50
51
52
53
54
55
void *llama_allocate_params(
    const char *prompt, int seed, int threads, int tokens, int top_k,
    float top_p, float temp, float repeat_penalty, int repeat_last_n,
    bool ignore_eos, bool memory_f16, int n_batch, int n_keep,
    const char **antiprompt, int antiprompt_count, float tfs_z, float typical_p,
    float frequency_penalty, float presence_penalty, int mirostat,
    float mirostat_eta, float mirostat_tau, bool penalize_nl,
Bruce MacDonald's avatar
Bruce MacDonald committed
56
57
    const char *logit_bias, bool mlock, bool mmap, const char *maingpu,
    const char *tensorsplit);
Jeffrey Morgan's avatar
Jeffrey Morgan committed
58
59
60

void llama_free_params(void *params_ptr);

Jeffrey Morgan's avatar
Jeffrey Morgan committed
61
void llama_binding_free_model(void *state);
Jeffrey Morgan's avatar
Jeffrey Morgan committed
62
63
64

int llama_predict(void *params_ptr, void *state_pr, char *result, bool debug);

Jeffrey Morgan's avatar
Jeffrey Morgan committed
65
66
67
68
69
#ifdef __cplusplus

}

#endif