Skip to content

Commit 2fb4f3a

Browse files
Ted ChangTed Chang
authored andcommitted
Resolve go test issue
go test ./embed_ollama_test.go:55:4: unknown field Embedding in struct literal of type ollamaResponse
1 parent 09732c9 commit 2fb4f3a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

‎embed_ollama_test.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ func TestNewEmbeddingFuncOllama(t *testing.T) {
1919
prompt := "hello world"
2020

2121
wantBody, err := json.Marshal(map[string]string{
22-
"model": model,
23-
"prompt": prompt,
22+
"model": model,
23+
"input": prompt,
2424
})
2525
if err != nil {
2626
t.Fatal("unexpected error:", err)
2727
}
28-
wantRes := []float32{-0.40824828, 0.40824828, 0.81649655} // normalized version of `{-0.1, 0.1, 0.2}`
28+
wantRes := [][]float32{{-0.40824828, 0.40824828, 0.81649655}} // normalized version of `{-0.1, 0.1, 0.2}`
2929

3030
// Mock server
3131
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
3232
// Check URL
33-
if !strings.HasSuffix(r.URL.Path, baseURLSuffix+"/embeddings") {
34-
t.Fatal("expected URL", baseURLSuffix+"/embeddings", "got", r.URL.Path)
33+
if !strings.HasSuffix(r.URL.Path, baseURLSuffix+"/embed") {
34+
t.Fatal("expected URL", baseURLSuffix+"/embed", "got", r.URL.Path)
3535
}
3636
// Check method
3737
if r.Method != "POST" {
@@ -52,7 +52,7 @@ func TestNewEmbeddingFuncOllama(t *testing.T) {
5252

5353
// Write response
5454
resp := ollamaResponse{
55-
Embedding: wantRes,
55+
Embeddings: wantRes,
5656
}
5757
w.WriteHeader(http.StatusOK)
5858
_ = json.NewEncoder(w).Encode(resp)
@@ -70,7 +70,7 @@ func TestNewEmbeddingFuncOllama(t *testing.T) {
7070
if err != nil {
7171
t.Fatal("expected nil, got", err)
7272
}
73-
if slices.Compare(wantRes, res) != 0 {
73+
if slices.Compare(wantRes[0], res) != 0 {
7474
t.Fatal("expected res", wantRes, "got", res)
7575
}
7676
}

0 commit comments

Comments
 (0)