mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-24 06:46:39 +00:00
fix: fix tests, small refactors
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
parent
982a7e86a8
commit
e459f114cd
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -29,6 +29,7 @@ jobs:
|
|||||||
|
|
||||||
sudo apt-get install -y ca-certificates cmake curl patch
|
sudo apt-get install -y ca-certificates cmake curl patch
|
||||||
sudo apt-get install -y libopencv-dev && sudo ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2
|
sudo apt-get install -y libopencv-dev && sudo ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2
|
||||||
|
sudo pip install -r extra/requirements.txt
|
||||||
|
|
||||||
sudo mkdir /build && sudo chmod -R 777 /build && cd /build && \
|
sudo mkdir /build && sudo chmod -R 777 /build && cd /build && \
|
||||||
curl -L "https://github.com/gabime/spdlog/archive/refs/tags/v1.11.0.tar.gz" | \
|
curl -L "https://github.com/gabime/spdlog/archive/refs/tags/v1.11.0.tar.gz" | \
|
||||||
@ -45,7 +46,6 @@ jobs:
|
|||||||
sudo cp -rfv /build/lib/Linux-$(uname -m)/piper_phonemize/lib/. /lib64/ && \
|
sudo cp -rfv /build/lib/Linux-$(uname -m)/piper_phonemize/lib/. /lib64/ && \
|
||||||
sudo cp -rfv /build/lib/Linux-$(uname -m)/piper_phonemize/lib/. /usr/lib/ && \
|
sudo cp -rfv /build/lib/Linux-$(uname -m)/piper_phonemize/lib/. /usr/lib/ && \
|
||||||
sudo cp -rfv /build/lib/Linux-$(uname -m)/piper_phonemize/include/. /usr/include/
|
sudo cp -rfv /build/lib/Linux-$(uname -m)/piper_phonemize/include/. /usr/include/
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
ESPEAK_DATA="/build/lib/Linux-$(uname -m)/piper_phonemize/lib/espeak-ng-data" GO_TAGS="tts stablediffusion" make test
|
ESPEAK_DATA="/build/lib/Linux-$(uname -m)/piper_phonemize/lib/espeak-ng-data" GO_TAGS="tts stablediffusion" make test
|
||||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,9 +3,10 @@ go-llama
|
|||||||
/gpt4all
|
/gpt4all
|
||||||
go-stable-diffusion
|
go-stable-diffusion
|
||||||
go-piper
|
go-piper
|
||||||
|
/go-bert
|
||||||
go-ggllm
|
go-ggllm
|
||||||
/piper
|
/piper
|
||||||
|
__pycache__/
|
||||||
*.a
|
*.a
|
||||||
get-sources
|
get-sources
|
||||||
|
|
||||||
|
@ -124,8 +124,11 @@ var _ = Describe("API test", func() {
|
|||||||
var c context.Context
|
var c context.Context
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
var tmpdir string
|
var tmpdir string
|
||||||
commonOpts := []options.AppOption{options.WithDebug(false),
|
|
||||||
options.WithDisableMessage(true)}
|
commonOpts := []options.AppOption{
|
||||||
|
options.WithDebug(true),
|
||||||
|
options.WithDisableMessage(true),
|
||||||
|
}
|
||||||
|
|
||||||
Context("API with ephemeral models", func() {
|
Context("API with ephemeral models", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
@ -145,7 +148,7 @@ var _ = Describe("API test", func() {
|
|||||||
Name: "bert2",
|
Name: "bert2",
|
||||||
URL: "https://raw.githubusercontent.com/go-skynet/model-gallery/main/bert-embeddings.yaml",
|
URL: "https://raw.githubusercontent.com/go-skynet/model-gallery/main/bert-embeddings.yaml",
|
||||||
Overrides: map[string]interface{}{"foo": "bar"},
|
Overrides: map[string]interface{}{"foo": "bar"},
|
||||||
AdditionalFiles: []gallery.File{gallery.File{Filename: "foo.yaml", URI: "https://raw.githubusercontent.com/go-skynet/model-gallery/main/bert-embeddings.yaml"}},
|
AdditionalFiles: []gallery.File{{Filename: "foo.yaml", URI: "https://raw.githubusercontent.com/go-skynet/model-gallery/main/bert-embeddings.yaml"}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
out, err := yaml.Marshal(g)
|
out, err := yaml.Marshal(g)
|
||||||
@ -421,64 +424,32 @@ var _ = Describe("API test", func() {
|
|||||||
os.RemoveAll(tmpdir)
|
os.RemoveAll(tmpdir)
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("API query", func() {
|
It("calculate embeddings with huggingface", func() {
|
||||||
BeforeEach(func() {
|
if runtime.GOOS != "linux" {
|
||||||
modelLoader = model.NewModelLoader(os.Getenv("MODELS_PATH"))
|
Skip("test supported only on linux")
|
||||||
c, cancel = context.WithCancel(context.Background())
|
}
|
||||||
|
resp, err := client.CreateEmbeddings(
|
||||||
|
context.Background(),
|
||||||
|
openai.EmbeddingRequest{
|
||||||
|
Model: openai.AdaCodeSearchCode,
|
||||||
|
Input: []string{"sun", "cat"},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(len(resp.Data[0].Embedding)).To(BeNumerically("==", 384))
|
||||||
|
Expect(len(resp.Data[1].Embedding)).To(BeNumerically("==", 384))
|
||||||
|
|
||||||
var err error
|
sunEmbedding := resp.Data[0].Embedding
|
||||||
app, err = App(
|
resp2, err := client.CreateEmbeddings(
|
||||||
append(commonOpts,
|
context.Background(),
|
||||||
options.WithDebug(true),
|
openai.EmbeddingRequest{
|
||||||
options.WithContext(c), options.WithModelLoader(modelLoader))...)
|
Model: openai.AdaCodeSearchCode,
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Input: []string{"sun"},
|
||||||
go app.Listen("127.0.0.1:9090")
|
},
|
||||||
|
)
|
||||||
defaultConfig := openai.DefaultConfig("")
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defaultConfig.BaseURL = "http://127.0.0.1:9090/v1"
|
Expect(resp2.Data[0].Embedding).To(Equal(sunEmbedding))
|
||||||
|
Expect(resp2.Data[0].Embedding).ToNot(Equal(resp.Data[1].Embedding))
|
||||||
client2 = openaigo.NewClient("")
|
|
||||||
client2.BaseURL = defaultConfig.BaseURL
|
|
||||||
|
|
||||||
// Wait for API to be ready
|
|
||||||
client = openai.NewClientWithConfig(defaultConfig)
|
|
||||||
Eventually(func() error {
|
|
||||||
_, err := client.ListModels(context.TODO())
|
|
||||||
return err
|
|
||||||
}, "2m").ShouldNot(HaveOccurred())
|
|
||||||
})
|
|
||||||
AfterEach(func() {
|
|
||||||
cancel()
|
|
||||||
app.Shutdown()
|
|
||||||
})
|
|
||||||
|
|
||||||
It("calculate embeddings with huggingface", func() {
|
|
||||||
if runtime.GOOS != "linux" {
|
|
||||||
Skip("test supported only on linux")
|
|
||||||
}
|
|
||||||
resp, err := client.CreateEmbeddings(
|
|
||||||
context.Background(),
|
|
||||||
openai.EmbeddingRequest{
|
|
||||||
Model: openai.AdaCodeSearchCode,
|
|
||||||
Input: []string{"sun", "cat"},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
Expect(len(resp.Data[0].Embedding)).To(BeNumerically("==", 384))
|
|
||||||
Expect(len(resp.Data[1].Embedding)).To(BeNumerically("==", 384))
|
|
||||||
|
|
||||||
sunEmbedding := resp.Data[0].Embedding
|
|
||||||
resp2, err := client.CreateEmbeddings(
|
|
||||||
context.Background(),
|
|
||||||
openai.EmbeddingRequest{
|
|
||||||
Model: openai.AdaCodeSearchCode,
|
|
||||||
Input: []string{"sun"},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
Expect(resp2.Data[0].Embedding).To(Equal(sunEmbedding))
|
|
||||||
Expect(resp2.Data[0].Embedding).ToNot(Equal(resp.Data[1].Embedding))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user