allocate a large enough tokens slice

This commit is contained in:
Michael Yang 2023-07-21 23:05:15 -07:00
parent 6d6b0d3321
commit b71c67b6ba

View file

@ -168,7 +168,7 @@ func (llm *llama) tokenize(prompt string) []C.llama_token {
cPrompt := C.CString(prompt)
defer C.free(unsafe.Pointer(cPrompt))
tokens := make([]C.llama_token, llm.NumCtx)
tokens := make([]C.llama_token, len(prompt)+1)
if n := C.llama_tokenize(llm.ctx, cPrompt, unsafe.SliceData(tokens), C.int(len(tokens)), true); n > 0 {
return tokens[:n]
}