fix: replace deprecated functions

This commit is contained in:
Michael Yang 2025-02-28 11:50:01 -08:00
parent a14912858e
commit 657685e85d

View File

@ -262,7 +262,7 @@ func LoadModelFromFile(modelPath string, params ModelParams) (*Model, error) {
cparams.progress_callback_user_data = unsafe.Pointer(&handle) cparams.progress_callback_user_data = unsafe.Pointer(&handle)
} }
m := Model{c: C.llama_load_model_from_file(C.CString(modelPath), cparams)} m := Model{c: C.llama_model_load_from_file(C.CString(modelPath), cparams)}
if m.c == nil { if m.c == nil {
return nil, fmt.Errorf("unable to load model: %s", modelPath) return nil, fmt.Errorf("unable to load model: %s", modelPath)
} }
@ -271,12 +271,12 @@ func LoadModelFromFile(modelPath string, params ModelParams) (*Model, error) {
} }
func FreeModel(model *Model) { func FreeModel(model *Model) {
C.llama_free_model(model.c) C.llama_model_free(model.c)
} }
func NewContextWithModel(model *Model, params ContextParams) (*Context, error) { func NewContextWithModel(model *Model, params ContextParams) (*Context, error) {
c := Context{ c := Context{
c: C.llama_new_context_with_model(model.c, params.c), c: C.llama_init_from_model(model.c, params.c),
numThreads: int(params.c.n_threads), numThreads: int(params.c.n_threads),
} }
if c.c == nil { if c.c == nil {
@ -287,15 +287,15 @@ func NewContextWithModel(model *Model, params ContextParams) (*Context, error) {
} }
func (m *Model) NumVocab() int { func (m *Model) NumVocab() int {
return int(C.llama_n_vocab(m.Vocab())) return int(C.llama_vocab_n_tokens(m.Vocab()))
} }
func (m *Model) TokenIsEog(token int) bool { func (m *Model) TokenIsEog(token int) bool {
return bool(C.llama_token_is_eog(m.Vocab(), C.llama_token(token))) return bool(C.llama_vocab_is_eog(m.Vocab(), C.llama_token(token)))
} }
func (m *Model) AddBOSToken() bool { func (m *Model) AddBOSToken() bool {
return bool(C.llama_add_bos_token(m.Vocab())) return bool(C.llama_vocab_get_add_bos(m.Vocab()))
} }
func (m *Model) ApplyLoraFromFile(context *Context, loraPath string, scale float32, threads int) error { func (m *Model) ApplyLoraFromFile(context *Context, loraPath string, scale float32, threads int) error {
@ -478,7 +478,7 @@ func (m *Model) Tokenize(text string, addSpecial bool, parseSpecial bool) ([]int
} }
func (m *Model) NEmbd() int { func (m *Model) NEmbd() int {
return int(C.llama_n_embd(m.c)) return int(C.llama_model_n_embd(m.c))
} }
func Quantize(infile, outfile string, ftype uint32) error { func Quantize(infile, outfile string, ftype uint32) error {