Skip to content

Commit f9f516e

Browse files
committed
fix: give priority between the listed backends
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent a76e4d0 commit f9f516e

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

pkg/model/initializers.go

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"slices"
910
"strings"
1011
"time"
1112

@@ -22,8 +23,11 @@ var Aliases map[string]string = map[string]string{
2223
}
2324

2425
const (
25-
LlamaGGML = "llama-ggml"
26-
LLamaCPP = "llama-cpp"
26+
LlamaGGML = "llama-ggml"
27+
LLamaCPP = "llama-cpp"
28+
29+
LLamaCPPFallback = "llama-cpp-fallback"
30+
2731
Gpt4AllLlamaBackend = "gpt4all-llama"
2832
Gpt4AllMptBackend = "gpt4all-mpt"
2933
Gpt4AllJBackend = "gpt4all-j"
@@ -62,6 +66,45 @@ ENTRY:
6266
backends = append(backends, e.Name())
6367
}
6468
}
69+
70+
// order backends from the asset directory.
71+
// as we scan for backends, we want to keep some order which backends are tried of.
72+
// for example, llama.cpp should be tried first, and we want to keep the huggingface backend at the last.
73+
74+
// sets a priority list
75+
// First has more priority
76+
priorityList := []string{
77+
// First llama.cpp and llama-ggml
78+
LLamaCPP, LLamaCPPFallback, LlamaGGML, Gpt4All,
79+
}
80+
toTheEnd := []string{
81+
// last has to be huggingface
82+
LCHuggingFaceBackend,
83+
// then bert embeddings
84+
BertEmbeddingsBackend,
85+
}
86+
slices.Reverse(priorityList)
87+
slices.Reverse(toTheEnd)
88+
89+
// order certain backends first
90+
for _, b := range priorityList {
91+
for i, be := range backends {
92+
if be == b {
93+
backends = append([]string{be}, append(backends[:i], backends[i+1:]...)...)
94+
break
95+
}
96+
}
97+
}
98+
// make sure that some others are pushed at the end
99+
for _, b := range toTheEnd {
100+
for i, be := range backends {
101+
if be == b {
102+
backends = append(append(backends[:i], backends[i+1:]...), be)
103+
break
104+
}
105+
}
106+
}
107+
65108
return backends, nil
66109
}
67110

0 commit comments

Comments
 (0)