sampling_ext.h 1.37 KB
Newer Older
1
// TODO: this is a temporary wrapper to allow calling C++ code from CGo
2
3
#ifndef SAMPLING_EXT_H
#define SAMPLING_EXT_H
4
5
6
7
8
9

#ifdef __cplusplus
extern "C"
{
#endif

10
11
    // Forward declaration to avoid include of "sampling.h" which has c++
    // includes
12
13
    struct common_sampler;
    struct common_sampler_cparams {
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
        int32_t top_k;
        float top_p;
        float min_p;
        float typical_p;
        float temp;
        int32_t penalty_last_n;
        float penalty_repeat;
        float penalty_freq;
        float penalty_present;
        int32_t mirostat;
        float mirostat_tau;
        float mirostat_eta;
        uint32_t seed;
        char *grammar;
    };

30
31
32
33
34
    struct common_sampler *common_sampler_cinit(const struct llama_model *model, struct common_sampler_cparams *params);
    void common_sampler_cfree(struct common_sampler *sampler);
    void common_sampler_creset(struct common_sampler *sampler);
    void common_sampler_caccept(struct common_sampler *sampler, llama_token id, bool apply_grammar);
    llama_token common_sampler_csample(struct common_sampler *sampler, struct llama_context *ctx, int idx);
35

36
37
    int schema_to_grammar(const char *json_schema, char *grammar, size_t max_len);

38
39
40
    struct llama_vocab * llama_load_vocab_from_file(const char * fname);
    void llama_free_vocab(struct llama_vocab * vocab);

41
42
43
44
#ifdef __cplusplus
}
#endif

45
#endif // SAMPLING_EXT_H