2024-04-17 21:33:49 +00:00
|
|
|
package startup_test
|
2024-01-05 22:16:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2024-06-24 15:32:12 +00:00
|
|
|
"github.com/mudler/LocalAI/core/config"
|
2024-06-23 08:24:36 +00:00
|
|
|
. "github.com/mudler/LocalAI/pkg/startup"
|
|
|
|
"github.com/mudler/LocalAI/pkg/utils"
|
2024-01-05 22:16:33 +00:00
|
|
|
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Preload test", func() {
|
|
|
|
|
|
|
|
Context("Preloading from strings", func() {
|
2024-01-27 23:14:16 +00:00
|
|
|
It("loads from remote url", func() {
|
|
|
|
tmpdir, err := os.MkdirTemp("", "")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
libraryURL := "https://raw.githubusercontent.com/mudler/LocalAI/master/embedded/model_library.yaml"
|
2024-07-11 13:04:05 +00:00
|
|
|
fileName := fmt.Sprintf("%s.yaml", "phi-2")
|
2024-01-27 23:14:16 +00:00
|
|
|
|
2024-07-10 11:18:32 +00:00
|
|
|
InstallModels([]config.Gallery{}, libraryURL, tmpdir, true, nil, "phi-2")
|
2024-01-27 23:14:16 +00:00
|
|
|
|
|
|
|
resultFile := filepath.Join(tmpdir, fileName)
|
|
|
|
|
|
|
|
content, err := os.ReadFile(resultFile)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(string(content)).To(ContainSubstring("name: phi-2"))
|
|
|
|
})
|
|
|
|
|
2024-01-05 22:16:33 +00:00
|
|
|
It("loads from embedded full-urls", func() {
|
|
|
|
tmpdir, err := os.MkdirTemp("", "")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
2024-10-30 09:57:21 +00:00
|
|
|
url := "https://raw.githubusercontent.com/mudler/LocalAI-examples/main/configurations/phi-2.yaml"
|
2024-07-11 13:04:05 +00:00
|
|
|
fileName := fmt.Sprintf("%s.yaml", "phi-2")
|
2024-01-05 22:16:33 +00:00
|
|
|
|
2024-07-10 11:18:32 +00:00
|
|
|
InstallModels([]config.Gallery{}, "", tmpdir, true, nil, url)
|
2024-01-05 22:16:33 +00:00
|
|
|
|
|
|
|
resultFile := filepath.Join(tmpdir, fileName)
|
|
|
|
|
|
|
|
content, err := os.ReadFile(resultFile)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(string(content)).To(ContainSubstring("name: phi-2"))
|
|
|
|
})
|
|
|
|
It("loads from embedded short-urls", func() {
|
|
|
|
tmpdir, err := os.MkdirTemp("", "")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
url := "phi-2"
|
|
|
|
|
2024-07-10 11:18:32 +00:00
|
|
|
InstallModels([]config.Gallery{}, "", tmpdir, true, nil, url)
|
2024-01-05 22:16:33 +00:00
|
|
|
|
|
|
|
entry, err := os.ReadDir(tmpdir)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(entry).To(HaveLen(1))
|
|
|
|
resultFile := entry[0].Name()
|
|
|
|
|
|
|
|
content, err := os.ReadFile(filepath.Join(tmpdir, resultFile))
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(string(content)).To(ContainSubstring("name: phi-2"))
|
|
|
|
})
|
|
|
|
It("loads from embedded models", func() {
|
|
|
|
tmpdir, err := os.MkdirTemp("", "")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
url := "mistral-openorca"
|
|
|
|
fileName := fmt.Sprintf("%s.yaml", utils.MD5(url))
|
|
|
|
|
2024-07-10 11:18:32 +00:00
|
|
|
InstallModels([]config.Gallery{}, "", tmpdir, true, nil, url)
|
2024-01-05 22:16:33 +00:00
|
|
|
|
|
|
|
resultFile := filepath.Join(tmpdir, fileName)
|
|
|
|
|
|
|
|
content, err := os.ReadFile(resultFile)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
Expect(string(content)).To(ContainSubstring("name: mistral-openorca"))
|
|
|
|
})
|
2024-07-11 13:04:05 +00:00
|
|
|
It("downloads from urls", func() {
|
|
|
|
tmpdir, err := os.MkdirTemp("", "")
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
url := "huggingface://TheBloke/TinyLlama-1.1B-Chat-v0.3-GGUF/tinyllama-1.1b-chat-v0.3.Q2_K.gguf"
|
|
|
|
fileName := fmt.Sprintf("%s.gguf", "tinyllama-1.1b-chat-v0.3.Q2_K")
|
|
|
|
|
|
|
|
err = InstallModels([]config.Gallery{}, "", tmpdir, false, nil, url)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
resultFile := filepath.Join(tmpdir, fileName)
|
|
|
|
|
|
|
|
_, err = os.Stat(resultFile)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
})
|
2024-01-05 22:16:33 +00:00
|
|
|
})
|
|
|
|
})
|