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

#ifdef __cplusplus
extern "C"
{
#endif

10
11
12
13
14
    // Forward declaration to avoid include of "sampling.h" which has c++
    // includes
    struct gpt_sampler;

    struct gpt_sampler_cparams
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    {
        int32_t top_k;
        float top_p;
        float min_p;
        float tfs_z;
        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;
    };

34
35
36
37
38
    struct gpt_sampler *gpt_sampler_cinit(
        const struct llama_model *model,
        struct gpt_sampler_cparams *params);
    void gpt_sampler_cfree(struct gpt_sampler *sampler);
    void gpt_sampler_creset(struct gpt_sampler *sampler);
39

40
41
    llama_token gpt_sampler_csample(
        struct gpt_sampler *sampler,
42
43
44
        struct llama_context *ctx_main,
        int idx);

45
46
    void gpt_sampler_caccept(
        struct gpt_sampler *sampler,
47
48
49
        llama_token id,
        bool apply_grammar);

50
51
    int schema_to_grammar(const char *json_schema, char *grammar, size_t max_len);

52
53
54
55
#ifdef __cplusplus
}
#endif

56
#endif // GPT_SAMPLER_EXT_H