sampling_ext.h 1.52 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
        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;
        uint32_t seed;
        char *grammar;
    };

27
28
29
30
31
    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);
32

33
34
    int schema_to_grammar(const char *json_schema, char *grammar, size_t max_len);

35
36
37
38
39
40

    struct llama_grammar *grammar_init(char* grammar, uint32_t* tokens, size_t n_tokens, const char** pieces, uint32_t* eog_tokens, size_t n_eog_tokens);
    void grammar_free(struct llama_grammar *g);
    void grammar_apply(struct llama_grammar *g, struct llama_token_data_array *tokens);
    void grammar_accept(struct llama_grammar *g, llama_token id);

41

42
43
44
45
#ifdef __cplusplus
}
#endif

46
#endif // SAMPLING_EXT_H