@ -5,10 +5,10 @@ package gpt4all
// #cgo darwin LDFLAGS: -framework Accelerate
// #cgo darwin CXXFLAGS: -std=c++17
// #cgo LDFLAGS: -lgpt4all -lm -lstdc++
// void* load_ gpt4all_ model(const char *fname, int n_threads);
// void gpt4all_ model_prompt( const char *prompt, void *m, char* result, int repeat_last_n, float repeat_penalty, int n_ctx, int tokens, int top_k,
// void* load_ model(const char *fname, int n_threads);
// void model_prompt( const char *prompt, void *m, char* result, int repeat_last_n, float repeat_penalty, int n_ctx, int tokens, int top_k,
// float top_p, float temp, int n_batch,float ctx_erase);
// void gpt4all_ free_model(void *state_ptr);
// void free_model(void *state_ptr);
// extern unsigned char getTokenCallback(void *, char *);
import "C"
import (
@ -27,7 +27,7 @@ type Model struct {
func New ( model string , opts ... ModelOption ) ( * Model , error ) {
ops := NewModelOptions ( opts ... )
state := C . load_ gpt4all_ model( C . CString ( model ) , C . int ( ops . Threads ) )
state := C . load_ model( C . CString ( model ) , C . int ( ops . Threads ) )
if state == nil {
return nil , fmt . Errorf ( "failed loading model" )
@ -52,7 +52,7 @@ func (l *Model) Predict(text string, opts ...PredictOption) (string, error) {
}
out := make ( [ ] byte , po . Tokens )
C . gpt4all_ model_prompt( input , l . state , ( * C . char ) ( unsafe . Pointer ( & out [ 0 ] ) ) , C . int ( po . RepeatLastN ) , C . float ( po . RepeatPenalty ) , C . int ( po . ContextSize ) ,
C . model_prompt( input , l . state , ( * C . char ) ( unsafe . Pointer ( & out [ 0 ] ) ) , C . int ( po . RepeatLastN ) , C . float ( po . RepeatPenalty ) , C . int ( po . ContextSize ) ,
C . int ( po . Tokens ) , C . int ( po . TopK ) , C . float ( po . TopP ) , C . float ( po . Temperature ) , C . int ( po . Batch ) , C . float ( po . ContextErase ) )
res := C . GoString ( ( * C . char ) ( unsafe . Pointer ( & out [ 0 ] ) ) )
@ -65,7 +65,7 @@ func (l *Model) Predict(text string, opts ...PredictOption) (string, error) {
}
func ( l * Model ) Free ( ) {
C . gpt4all_ free_model( l . state )
C . free_model( l . state )
}
func ( l * Model ) SetTokenCallback ( callback func ( token string ) bool ) {