|
|
|
@ -124,8 +124,11 @@ var _ = Describe("API test", func() { |
|
|
|
|
var c context.Context |
|
|
|
|
var cancel context.CancelFunc |
|
|
|
|
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() { |
|
|
|
|
BeforeEach(func() { |
|
|
|
@ -145,7 +148,7 @@ var _ = Describe("API test", func() { |
|
|
|
|
Name: "bert2", |
|
|
|
|
URL: "https://raw.githubusercontent.com/go-skynet/model-gallery/main/bert-embeddings.yaml", |
|
|
|
|
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) |
|
|
|
@ -421,64 +424,32 @@ var _ = Describe("API test", func() { |
|
|
|
|
os.RemoveAll(tmpdir) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
Context("API query", func() { |
|
|
|
|
BeforeEach(func() { |
|
|
|
|
modelLoader = model.NewModelLoader(os.Getenv("MODELS_PATH")) |
|
|
|
|
c, cancel = context.WithCancel(context.Background()) |
|
|
|
|
|
|
|
|
|
var err error |
|
|
|
|
app, err = App( |
|
|
|
|
append(commonOpts, |
|
|
|
|
options.WithDebug(true), |
|
|
|
|
options.WithContext(c), options.WithModelLoader(modelLoader))...) |
|
|
|
|
Expect(err).ToNot(HaveOccurred()) |
|
|
|
|
go app.Listen("127.0.0.1:9090") |
|
|
|
|
|
|
|
|
|
defaultConfig := openai.DefaultConfig("") |
|
|
|
|
defaultConfig.BaseURL = "http://127.0.0.1:9090/v1" |
|
|
|
|
|
|
|
|
|
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)) |
|
|
|
|
|
|
|
|
|
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)) |
|
|
|
|
}) |
|
|
|
|
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)) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|