|
|
@ -2,6 +2,8 @@ package api |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"os" |
|
|
|
|
|
|
|
"path/filepath" |
|
|
|
"regexp" |
|
|
|
"regexp" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"sync" |
|
|
|
"sync" |
|
|
@ -102,7 +104,7 @@ func ModelEmbedding(s string, tokens []int, loader *model.ModelLoader, c Config) |
|
|
|
switch model := inferenceModel.(type) { |
|
|
|
switch model := inferenceModel.(type) { |
|
|
|
case *llama.LLama: |
|
|
|
case *llama.LLama: |
|
|
|
fn = func() ([]float32, error) { |
|
|
|
fn = func() ([]float32, error) { |
|
|
|
predictOptions := buildLLamaPredictOptions(c) |
|
|
|
predictOptions := buildLLamaPredictOptions(c, loader.ModelPath) |
|
|
|
if len(tokens) > 0 { |
|
|
|
if len(tokens) > 0 { |
|
|
|
return model.TokenEmbeddings(tokens, predictOptions...) |
|
|
|
return model.TokenEmbeddings(tokens, predictOptions...) |
|
|
|
} |
|
|
|
} |
|
|
@ -151,7 +153,7 @@ func ModelEmbedding(s string, tokens []int, loader *model.ModelLoader, c Config) |
|
|
|
}, nil |
|
|
|
}, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func buildLLamaPredictOptions(c Config) []llama.PredictOption { |
|
|
|
func buildLLamaPredictOptions(c Config, modelPath string) []llama.PredictOption { |
|
|
|
// Generate the prediction using the language model
|
|
|
|
// Generate the prediction using the language model
|
|
|
|
predictOptions := []llama.PredictOption{ |
|
|
|
predictOptions := []llama.PredictOption{ |
|
|
|
llama.SetTemperature(c.Temperature), |
|
|
|
llama.SetTemperature(c.Temperature), |
|
|
@ -161,6 +163,17 @@ func buildLLamaPredictOptions(c Config) []llama.PredictOption { |
|
|
|
llama.SetThreads(c.Threads), |
|
|
|
llama.SetThreads(c.Threads), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if c.PromptCacheAll { |
|
|
|
|
|
|
|
predictOptions = append(predictOptions, llama.EnablePromptCacheAll) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if c.PromptCachePath != "" { |
|
|
|
|
|
|
|
// Create parent directory
|
|
|
|
|
|
|
|
p := filepath.Join(modelPath, c.PromptCachePath) |
|
|
|
|
|
|
|
os.MkdirAll(filepath.Dir(p), 0755) |
|
|
|
|
|
|
|
predictOptions = append(predictOptions, llama.SetPathPromptCache(p)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if c.Mirostat != 0 { |
|
|
|
if c.Mirostat != 0 { |
|
|
|
predictOptions = append(predictOptions, llama.SetMirostat(c.Mirostat)) |
|
|
|
predictOptions = append(predictOptions, llama.SetMirostat(c.Mirostat)) |
|
|
|
} |
|
|
|
} |
|
|
@ -469,7 +482,7 @@ func ModelInference(s string, loader *model.ModelLoader, c Config, tokenCallback |
|
|
|
model.SetTokenCallback(tokenCallback) |
|
|
|
model.SetTokenCallback(tokenCallback) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
predictOptions := buildLLamaPredictOptions(c) |
|
|
|
predictOptions := buildLLamaPredictOptions(c, loader.ModelPath) |
|
|
|
|
|
|
|
|
|
|
|
str, er := model.Predict( |
|
|
|
str, er := model.Predict( |
|
|
|
s, |
|
|
|
s, |
|
|
|