mirror of
https://github.com/mudler/LocalAI.git
synced 2025-05-20 02:24:59 +00:00
feat: Centralized Request Processing middleware (#3847)
* squash past, centralize request middleware PR Signed-off-by: Dave Lee <dave@gray101.com> * migrate bruno request files to examples repo Signed-off-by: Dave Lee <dave@gray101.com> * fix Signed-off-by: Dave Lee <dave@gray101.com> * Update tests/e2e-aio/e2e_test.go Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> --------- Signed-off-by: Dave Lee <dave@gray101.com> Signed-off-by: Ettore Di Giacinto <mudler@users.noreply.github.com> Co-authored-by: Ettore Di Giacinto <mudler@users.noreply.github.com>
This commit is contained in:
parent
c330360785
commit
3cddf24747
53 changed files with 240975 additions and 821 deletions
|
@ -43,7 +43,7 @@ var _ = BeforeSuite(func() {
|
|||
apiEndpoint = "http://localhost:" + apiPort + "/v1" // So that other tests can reference this value safely.
|
||||
defaultConfig.BaseURL = apiEndpoint
|
||||
} else {
|
||||
fmt.Println("Default ", apiEndpoint)
|
||||
GinkgoWriter.Printf("docker apiEndpoint set from env: %q\n", apiEndpoint)
|
||||
defaultConfig = openai.DefaultConfig(apiKey)
|
||||
defaultConfig.BaseURL = apiEndpoint
|
||||
}
|
||||
|
@ -95,10 +95,11 @@ func startDockerImage() {
|
|||
PortBindings: map[docker.Port][]docker.PortBinding{
|
||||
"8080/tcp": []docker.PortBinding{{HostPort: apiPort}},
|
||||
},
|
||||
Env: []string{"MODELS_PATH=/models", "DEBUG=true", "THREADS=" + fmt.Sprint(proc)},
|
||||
Env: []string{"MODELS_PATH=/models", "DEBUG=true", "THREADS=" + fmt.Sprint(proc), "LOCALAI_SINGLE_ACTIVE_BACKEND=true"},
|
||||
Mounts: []string{md + ":/models"},
|
||||
}
|
||||
|
||||
GinkgoWriter.Printf("Launching Docker Container %q\n%+v\n", containerImageTag, options)
|
||||
r, err := pool.RunWithOptions(options)
|
||||
Expect(err).To(Not(HaveOccurred()))
|
||||
|
||||
|
|
|
@ -121,14 +121,13 @@ var _ = Describe("E2E test", func() {
|
|||
|
||||
Context("images", func() {
|
||||
It("correctly", func() {
|
||||
resp, err := client.CreateImage(context.TODO(),
|
||||
openai.ImageRequest{
|
||||
Prompt: "test",
|
||||
Quality: "1",
|
||||
Size: openai.CreateImageSize256x256,
|
||||
},
|
||||
)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
req := openai.ImageRequest{
|
||||
Prompt: "test",
|
||||
Quality: "1",
|
||||
Size: openai.CreateImageSize256x256,
|
||||
}
|
||||
resp, err := client.CreateImage(context.TODO(), req)
|
||||
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("error sending image request %+v", req))
|
||||
Expect(len(resp.Data)).To(Equal(1), fmt.Sprint(resp))
|
||||
Expect(resp.Data[0].URL).To(ContainSubstring("png"), fmt.Sprint(resp.Data[0].URL))
|
||||
})
|
||||
|
@ -232,13 +231,42 @@ var _ = Describe("E2E test", func() {
|
|||
Expect(resp.Text).To(ContainSubstring("This is the"), fmt.Sprint(resp.Text))
|
||||
})
|
||||
})
|
||||
Context("vad", func() {
|
||||
It("correctly", func() {
|
||||
modelName := "silero-vad"
|
||||
req := schema.VADRequest{
|
||||
BasicModelRequest: schema.BasicModelRequest{
|
||||
Model: modelName,
|
||||
},
|
||||
Audio: SampleVADAudio, // Use hardcoded sample data for now.
|
||||
}
|
||||
serialized, err := json.Marshal(req)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(serialized).ToNot(BeNil())
|
||||
|
||||
vadEndpoint := apiEndpoint + "/vad"
|
||||
resp, err := http.Post(vadEndpoint, "application/json", bytes.NewReader(serialized))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(resp).ToNot(BeNil())
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(resp.StatusCode).To(Equal(200))
|
||||
deserializedResponse := schema.VADResponse{}
|
||||
err = json.Unmarshal(body, &deserializedResponse)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(deserializedResponse).ToNot(BeZero())
|
||||
Expect(deserializedResponse.Segments).ToNot(BeZero())
|
||||
})
|
||||
})
|
||||
Context("reranker", func() {
|
||||
It("correctly", func() {
|
||||
modelName := "jina-reranker-v1-base-en"
|
||||
|
||||
req := schema.JINARerankRequest{
|
||||
Model: modelName,
|
||||
BasicModelRequest: schema.BasicModelRequest{
|
||||
Model: modelName,
|
||||
},
|
||||
Query: "Organic skincare products for sensitive skin",
|
||||
Documents: []string{
|
||||
"Eco-friendly kitchenware for modern homes",
|
||||
|
|
240009
tests/e2e-aio/sample_data_test.go
Normal file
240009
tests/e2e-aio/sample_data_test.go
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue