@@ -20,19 +20,6 @@ const (
2020 Name = "llama.cpp"
2121)
2222
23- // VendoredServerStoragePath returns the parent path of the vendored version of
24- // com.docker.llama-server. It can be overridden during init().
25- var VendoredServerStoragePath = func () (string , error ) {
26- return "." , nil
27- }
28-
29- // UpdatedServerStoragePath returns the parent path of the updated version of
30- // com.docker.llama-server. It is also where updates will be stored when
31- // downloaded. It can be overridden during init().
32- var UpdatedServerStoragePath = func () (string , error ) {
33- return "." , nil
34- }
35-
3623// llamaCpp is the llama.cpp-based backend implementation.
3724type llamaCpp struct {
3825 // log is the associated logger.
@@ -42,18 +29,27 @@ type llamaCpp struct {
4229 // serverLog is the logger to use for the llama.cpp server process.
4330 serverLog logging.Logger
4431 updatedLlamaCpp bool
32+ // vendoredServerStoragePath is the parent path of the vendored version of com.docker.llama-server.
33+ vendoredServerStoragePath string
34+ // updatedServerStoragePath is the parent path of the updated version of com.docker.llama-server.
35+ // It is also where updates will be stored when downloaded.
36+ updatedServerStoragePath string
4537}
4638
4739// New creates a new llama.cpp-based backend.
4840func New (
4941 log logging.Logger ,
5042 modelManager * models.Manager ,
5143 serverLog logging.Logger ,
44+ vendoredServerStoragePath string ,
45+ updatedServerStoragePath string ,
5246) (inference.Backend , error ) {
5347 return & llamaCpp {
54- log : log ,
55- modelManager : modelManager ,
56- serverLog : serverLog ,
48+ log : log ,
49+ modelManager : modelManager ,
50+ serverLog : serverLog ,
51+ vendoredServerStoragePath : vendoredServerStoragePath ,
52+ updatedServerStoragePath : updatedServerStoragePath ,
5753 }, nil
5854}
5955
@@ -82,11 +78,7 @@ func (l *llamaCpp) Install(ctx context.Context, httpClient *http.Client) error {
8278 // Internet access and an available docker/docker-model-backend-llamacpp:latest-update on Docker Hub are required.
8379 // Even if docker/docker-model-backend-llamacpp:latest-update has been downloaded before, we still require its
8480 // digest to be equal to the one on Docker Hub.
85- llamaCppStorage , err := UpdatedServerStoragePath ()
86- if err != nil {
87- return fmt .Errorf ("unable to determine llama.cpp path: %w" , err )
88- }
89- llamaCppPath := filepath .Join (llamaCppStorage , "com.docker.llama-server" )
81+ llamaCppPath := filepath .Join (l .updatedServerStoragePath , "com.docker.llama-server" )
9082 if err := ensureLatestLlamaCpp (ctx , l .log , httpClient , llamaCppPath ); err != nil {
9183 l .log .Infof ("failed to ensure latest llama.cpp: %v\n " , err )
9284 if errors .Is (err , context .Canceled ) {
@@ -112,15 +104,9 @@ func (l *llamaCpp) Run(ctx context.Context, socket, model string, mode inference
112104 l .log .Warnln ("llama.cpp may not be able to start" )
113105 }
114106
115- binPath , err := UpdatedServerStoragePath ()
116- if err != nil {
117- return fmt .Errorf ("unable to determine llama.cpp path: %w" , err )
118- }
119- if ! l .updatedLlamaCpp {
120- binPath , err = VendoredServerStoragePath ()
121- if err != nil {
122- return fmt .Errorf ("unable to determine vendored llama.cpp path: %w" , err )
123- }
107+ binPath := l .vendoredServerStoragePath
108+ if l .updatedLlamaCpp {
109+ binPath = l .updatedServerStoragePath
124110 }
125111 llamaCppArgs := []string {"--model" , modelPath , "--jinja" }
126112 if mode == inference .BackendModeEmbedding {
0 commit comments