sampling_ext.h 1.27 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
30
        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;
        bool penalize_nl;
        uint32_t seed;
        char *grammar;
    };

31
32
33
34
35
    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);
36

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

39
40
41
42
#ifdef __cplusplus
}
#endif

43
#endif // SAMPLING_EXT_H