Skip to content

Commit 63a60db

Browse files
committed
refactor: move main close to implementation for every backend
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent d02f6bf commit 63a60db

File tree

31 files changed

+97
-112
lines changed

31 files changed

+97
-112
lines changed

Makefile

+17-17
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ backend-assets/grpc:
403403
backend-assets/grpc/llama: backend-assets/grpc go-llama/libbinding.a
404404
$(GOCMD) mod edit -replace github.com/go-skynet/go-llama.cpp=$(shell pwd)/go-llama
405405
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-llama LIBRARY_PATH=$(shell pwd)/go-llama \
406-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/llama ./cmd/grpc/llama/
406+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/llama ./backend/go/llm/llama/
407407
# TODO: every binary should have its own folder instead, so can have different metal implementations
408408
ifeq ($(BUILD_TYPE),metal)
409409
cp go-llama/build/bin/ggml-metal.metal backend-assets/grpc/
@@ -443,68 +443,68 @@ endif
443443
backend-assets/grpc/llama-stable: backend-assets/grpc go-llama-stable/libbinding.a
444444
$(GOCMD) mod edit -replace github.com/go-skynet/go-llama.cpp=$(shell pwd)/go-llama-stable
445445
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-llama-stable LIBRARY_PATH=$(shell pwd)/go-llama \
446-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/llama-stable ./cmd/grpc/llama-stable/
446+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/llama-stable ./backend/go/llm/llama-stable/
447447

448448
backend-assets/grpc/gpt4all: backend-assets/grpc backend-assets/gpt4all gpt4all/gpt4all-bindings/golang/libgpt4all.a
449449
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/gpt4all/gpt4all-bindings/golang/ LIBRARY_PATH=$(shell pwd)/gpt4all/gpt4all-bindings/golang/ \
450-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/gpt4all ./cmd/grpc/gpt4all/
450+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/gpt4all ./backend/go/llm/gpt4all/
451451

452452
backend-assets/grpc/dolly: backend-assets/grpc go-ggml-transformers/libtransformers.a
453453
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-ggml-transformers LIBRARY_PATH=$(shell pwd)/go-ggml-transformers \
454-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/dolly ./cmd/grpc/dolly/
454+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/dolly ./backend/go/llm/dolly/
455455

456456
backend-assets/grpc/gpt2: backend-assets/grpc go-ggml-transformers/libtransformers.a
457457
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-ggml-transformers LIBRARY_PATH=$(shell pwd)/go-ggml-transformers \
458-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/gpt2 ./cmd/grpc/gpt2/
458+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/gpt2 ./backend/go/llm/gpt2/
459459

460460
backend-assets/grpc/gptj: backend-assets/grpc go-ggml-transformers/libtransformers.a
461461
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-ggml-transformers LIBRARY_PATH=$(shell pwd)/go-ggml-transformers \
462-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/gptj ./cmd/grpc/gptj/
462+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/gptj ./backend/go/llm/gptj/
463463

464464
backend-assets/grpc/gptneox: backend-assets/grpc go-ggml-transformers/libtransformers.a
465465
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-ggml-transformers LIBRARY_PATH=$(shell pwd)/go-ggml-transformers \
466-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/gptneox ./cmd/grpc/gptneox/
466+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/gptneox ./backend/go/llm/gptneox/
467467

468468
backend-assets/grpc/mpt: backend-assets/grpc go-ggml-transformers/libtransformers.a
469469
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-ggml-transformers LIBRARY_PATH=$(shell pwd)/go-ggml-transformers \
470-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/mpt ./cmd/grpc/mpt/
470+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/mpt ./backend/go/llm/mpt/
471471

472472
backend-assets/grpc/replit: backend-assets/grpc go-ggml-transformers/libtransformers.a
473473
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-ggml-transformers LIBRARY_PATH=$(shell pwd)/go-ggml-transformers \
474-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/replit ./cmd/grpc/replit/
474+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/replit ./backend/go/llm/replit/
475475

476476
backend-assets/grpc/falcon-ggml: backend-assets/grpc go-ggml-transformers/libtransformers.a
477477
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-ggml-transformers LIBRARY_PATH=$(shell pwd)/go-ggml-transformers \
478-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/falcon-ggml ./cmd/grpc/falcon-ggml/
478+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/falcon-ggml ./backend/go/llm/falcon-ggml/
479479

480480
backend-assets/grpc/starcoder: backend-assets/grpc go-ggml-transformers/libtransformers.a
481481
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-ggml-transformers LIBRARY_PATH=$(shell pwd)/go-ggml-transformers \
482-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/starcoder ./cmd/grpc/starcoder/
482+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/starcoder ./backend/go/llm/starcoder/
483483

484484
backend-assets/grpc/rwkv: backend-assets/grpc go-rwkv/librwkv.a
485485
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-rwkv LIBRARY_PATH=$(shell pwd)/go-rwkv \
486-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/rwkv ./cmd/grpc/rwkv/
486+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/rwkv ./backend/go/llm/rwkv
487487

488488
backend-assets/grpc/bert-embeddings: backend-assets/grpc go-bert/libgobert.a
489489
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-bert LIBRARY_PATH=$(shell pwd)/go-bert \
490-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/bert-embeddings ./cmd/grpc/bert-embeddings/
490+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/bert-embeddings ./backend/go/llm/bert/
491491

492492
backend-assets/grpc/langchain-huggingface: backend-assets/grpc
493-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/langchain-huggingface ./cmd/grpc/langchain-huggingface/
493+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/langchain-huggingface ./backend/go/llm/langchain/
494494

495495
backend-assets/grpc/stablediffusion: backend-assets/grpc
496496
if [ ! -f backend-assets/grpc/stablediffusion ]; then \
497497
$(MAKE) go-stable-diffusion/libstablediffusion.a; \
498498
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/go-stable-diffusion/ LIBRARY_PATH=$(shell pwd)/go-stable-diffusion/ \
499-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/stablediffusion ./cmd/grpc/stablediffusion/; \
499+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/stablediffusion ./backend/go/image/; \
500500
fi
501501

502502
backend-assets/grpc/piper: backend-assets/grpc backend-assets/espeak-ng-data go-piper/libpiper_binding.a
503503
CGO_CXXFLAGS="$(PIPER_CGO_CXXFLAGS)" CGO_LDFLAGS="$(PIPER_CGO_LDFLAGS)" LIBRARY_PATH=$(shell pwd)/go-piper \
504-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/piper ./cmd/grpc/piper/
504+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/piper ./backend/go/tts/piper/
505505

506506
backend-assets/grpc/whisper: backend-assets/grpc whisper.cpp/libwhisper.a
507507
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(shell pwd)/whisper.cpp LIBRARY_PATH=$(shell pwd)/whisper.cpp \
508-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/whisper ./cmd/grpc/whisper/
508+
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/whisper ./backend/go/transcribe/
509509

510510
grpcs: prepare $(GRPC_BACKENDS)

cmd/grpc/bert-embeddings/main.go backend/go/image/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package main
55
import (
66
"flag"
77

8-
bert "github.com/go-skynet/LocalAI/backend/go/llm/bert"
98
grpc "github.com/go-skynet/LocalAI/pkg/grpc"
109
)
1110

@@ -16,7 +15,7 @@ var (
1615
func main() {
1716
flag.Parse()
1817

19-
if err := grpc.StartServer(*addr, &bert.Embeddings{}); err != nil {
18+
if err := grpc.StartServer(*addr, &StableDiffusion{}); err != nil {
2019
panic(err)
2120
}
2221
}

backend/go/image/stablediffusion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package image
1+
package main
22

33
// This is a wrapper to statisfy the GRPC service interface
44
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)

backend/go/llm/bert/bert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package bert
1+
package main
22

33
// This is a wrapper to statisfy the GRPC service interface
44
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)

cmd/grpc/rwkv/main.go backend/go/llm/bert/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ package main
55
import (
66
"flag"
77

8-
rwkv "github.com/go-skynet/LocalAI/backend/go/llm/rwkv"
9-
108
grpc "github.com/go-skynet/LocalAI/pkg/grpc"
119
)
1210

@@ -17,7 +15,7 @@ var (
1715
func main() {
1816
flag.Parse()
1917

20-
if err := grpc.StartServer(*addr, &rwkv.LLM{}); err != nil {
18+
if err := grpc.StartServer(*addr, &Embeddings{}); err != nil {
2119
panic(err)
2220
}
2321
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

backend/go/llm/gpt4all/gpt4all.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gpt4all
1+
package main
22

33
// This is a wrapper to statisfy the GRPC service interface
44
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)
File renamed without changes.
File renamed without changes.
File renamed without changes.

backend/go/llm/langchain/langchain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package langchain
1+
package main
22

33
// This is a wrapper to statisfy the GRPC service interface
44
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)

cmd/grpc/stablediffusion/main.go backend/go/llm/langchain/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ package main
55
import (
66
"flag"
77

8-
image "github.com/go-skynet/LocalAI/backend/go/image"
9-
108
grpc "github.com/go-skynet/LocalAI/pkg/grpc"
119
)
1210

@@ -17,7 +15,7 @@ var (
1715
func main() {
1816
flag.Parse()
1917

20-
if err := grpc.StartServer(*addr, &image.StableDiffusion{}); err != nil {
18+
if err := grpc.StartServer(*addr, &LLM{}); err != nil {
2119
panic(err)
2220
}
2321
}

backend/go/llm/llama-stable/llama.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package llama
1+
package main
22

33
// This is a wrapper to statisfy the GRPC service interface
44
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)

cmd/grpc/llama-stable/main.go backend/go/llm/llama-stable/main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package main
33
import (
44
"flag"
55

6-
llama "github.com/go-skynet/LocalAI/backend/go/llm/llama-stable"
7-
86
grpc "github.com/go-skynet/LocalAI/pkg/grpc"
97
)
108

@@ -15,7 +13,7 @@ var (
1513
func main() {
1614
flag.Parse()
1715

18-
if err := grpc.StartServer(*addr, &llama.LLM{}); err != nil {
16+
if err := grpc.StartServer(*addr, &LLM{}); err != nil {
1917
panic(err)
2018
}
2119
}

backend/go/llm/llama/llama.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package llama
1+
package main
22

33
// This is a wrapper to statisfy the GRPC service interface
44
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package main
22

3+
// GRPC Falcon server
4+
35
// Note: this is started internally by LocalAI and a server is allocated for each model
46

57
import (
68
"flag"
79

8-
tts "github.com/go-skynet/LocalAI/backend/go/tts"
9-
1010
grpc "github.com/go-skynet/LocalAI/pkg/grpc"
1111
)
1212

@@ -17,7 +17,7 @@ var (
1717
func main() {
1818
flag.Parse()
1919

20-
if err := grpc.StartServer(*addr, &tts.Piper{}); err != nil {
20+
if err := grpc.StartServer(*addr, &LLM{}); err != nil {
2121
panic(err)
2222
}
2323
}
File renamed without changes.
File renamed without changes.

backend/go/llm/rwkv/main.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
// Note: this is started internally by LocalAI and a server is allocated for each model
4+
5+
import (
6+
"flag"
7+
8+
grpc "github.com/go-skynet/LocalAI/pkg/grpc"
9+
)
10+
11+
var (
12+
addr = flag.String("addr", "localhost:50051", "the address to connect to")
13+
)
14+
15+
func main() {
16+
flag.Parse()
17+
18+
if err := grpc.StartServer(*addr, &LLM{}); err != nil {
19+
panic(err)
20+
}
21+
}

backend/go/llm/rwkv/rwkv.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package rwkv
1+
package main
22

33
// This is a wrapper to statisfy the GRPC service interface
44
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)
File renamed without changes.

backend/go/transcribe/main.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
// Note: this is started internally by LocalAI and a server is allocated for each model
4+
5+
import (
6+
"flag"
7+
8+
grpc "github.com/go-skynet/LocalAI/pkg/grpc"
9+
)
10+
11+
var (
12+
addr = flag.String("addr", "localhost:50051", "the address to connect to")
13+
)
14+
15+
func main() {
16+
flag.Parse()
17+
18+
if err := grpc.StartServer(*addr, &Whisper{}); err != nil {
19+
panic(err)
20+
}
21+
}

backend/go/transcribe/transcript.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package transcribe
1+
package main
22

33
import (
44
"fmt"

backend/go/transcribe/whisper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package transcribe
1+
package main
22

33
// This is a wrapper to statisfy the GRPC service interface
44
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)

backend/go/tts/main.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
// Note: this is started internally by LocalAI and a server is allocated for each model
4+
5+
import (
6+
"flag"
7+
8+
grpc "github.com/go-skynet/LocalAI/pkg/grpc"
9+
)
10+
11+
var (
12+
addr = flag.String("addr", "localhost:50051", "the address to connect to")
13+
)
14+
15+
func main() {
16+
flag.Parse()
17+
18+
if err := grpc.StartServer(*addr, &Piper{}); err != nil {
19+
panic(err)
20+
}
21+
}

backend/go/tts/piper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package tts
1+
package main
22

33
// This is a wrapper to statisfy the GRPC service interface
44
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)

cmd/grpc/langchain-huggingface/main.go

-23
This file was deleted.

cmd/grpc/llama/main.go

-25
This file was deleted.

cmd/grpc/whisper/main.go

-23
This file was deleted.

0 commit comments

Comments
 (0)