|
@@ -272,76 +272,6 @@ func Test_Routes(t *testing.T) {
|
|
|
assert.Equal(t, "library", retrieveResp.OwnedBy)
|
|
|
},
|
|
|
},
|
|
|
- {
|
|
|
- Name: "Embed Handler Empty Input",
|
|
|
- Method: http.MethodPost,
|
|
|
- Path: "/api/embed",
|
|
|
- Setup: func(t *testing.T, req *http.Request) {
|
|
|
- embedReq := api.EmbedRequest{
|
|
|
- Model: "t-bone",
|
|
|
- Input: "",
|
|
|
- }
|
|
|
- jsonData, err := json.Marshal(embedReq)
|
|
|
- require.NoError(t, err)
|
|
|
- req.Body = io.NopCloser(bytes.NewReader(jsonData))
|
|
|
- },
|
|
|
- Expected: func(t *testing.T, resp *http.Response) {
|
|
|
- contentType := resp.Header.Get("Content-Type")
|
|
|
- if contentType != "application/json; charset=utf-8" {
|
|
|
- t.Fatalf("expected content type application/json; charset=utf-8, got %s", contentType)
|
|
|
- }
|
|
|
- body, err := io.ReadAll(resp.Body)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- var embedResp api.EmbedResponse
|
|
|
- err = json.Unmarshal(body, &embedResp)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- if embedResp.Model != "t-bone" {
|
|
|
- t.Fatalf("expected model t-bone, got %s", embedResp.Model)
|
|
|
- }
|
|
|
-
|
|
|
- if embedResp.Embeddings == nil {
|
|
|
- t.Fatalf("expected embeddings to not be nil, got %v", embedResp.Embeddings)
|
|
|
- }
|
|
|
-
|
|
|
- if len(embedResp.Embeddings) != 0 {
|
|
|
- t.Fatalf("expected embeddings to be empty, got %v", embedResp.Embeddings)
|
|
|
- }
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- Name: "Embed Handler Invalid Input",
|
|
|
- Method: http.MethodPost,
|
|
|
- Path: "/api/embed",
|
|
|
- Setup: func(t *testing.T, req *http.Request) {
|
|
|
- embedReq := api.EmbedRequest{
|
|
|
- Model: "t-bone",
|
|
|
- Input: 2,
|
|
|
- }
|
|
|
- jsonData, err := json.Marshal(embedReq)
|
|
|
- require.NoError(t, err)
|
|
|
- req.Body = io.NopCloser(bytes.NewReader(jsonData))
|
|
|
- },
|
|
|
- Expected: func(t *testing.T, resp *http.Response) {
|
|
|
- contentType := resp.Header.Get("Content-Type")
|
|
|
- if contentType != "application/json; charset=utf-8" {
|
|
|
- t.Fatalf("expected content type application/json; charset=utf-8, got %s", contentType)
|
|
|
- }
|
|
|
- _, err := io.ReadAll(resp.Body)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
- if resp.StatusCode != http.StatusBadRequest {
|
|
|
- t.Fatalf("expected status code 400, got %d", resp.StatusCode)
|
|
|
- }
|
|
|
- },
|
|
|
- },
|
|
|
}
|
|
|
|
|
|
t.Setenv("OLLAMA_MODELS", t.TempDir())
|