(t *testing.T)
| 35 | ) |
| 36 | |
| 37 | func TestClientRank(t *testing.T) { |
| 38 | testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 39 | assert.Equal(t, http.MethodPost, r.Method) |
| 40 | assert.Equal(t, rerankPath, r.URL.Path) |
| 41 | assert.Equal(t, applicationJSON, r.Header.Get(contentTypeHeader)) |
| 42 | assert.Contains(t, r.Header.Get("Authorization"), "Bearer") |
| 43 | |
| 44 | var req RankInput |
| 45 | err := json.NewDecoder(r.Body).Decode(&req) |
| 46 | require.NoError(t, err) |
| 47 | |
| 48 | assert.Equal(t, testQuery, req.Query) |
| 49 | assert.Equal(t, []string{"doc1", "doc2", "doc3"}, req.Documents) |
| 50 | assert.Equal(t, testModel, req.Model) |
| 51 | |
| 52 | response := RankResponse{ |
| 53 | Results: []RerankedResult{ |
| 54 | {Index: 0, RelevanceScore: 0.9}, |
| 55 | {Index: 2, RelevanceScore: 0.8}, |
| 56 | {Index: 1, RelevanceScore: 0.7}, |
| 57 | }, |
| 58 | } |
| 59 | |
| 60 | w.Header().Set(contentTypeHeader, applicationJSON) |
| 61 | json.NewEncoder(w).Encode(response) |
| 62 | })) |
| 63 | defer testServer.Close() |
| 64 | |
| 65 | client := &client{ |
| 66 | apiKey: testAPIKey, |
| 67 | httpClient: &http.Client{Timeout: 30 * time.Second}, |
| 68 | host: testServer.URL, |
| 69 | path: rerankPath, |
| 70 | maxDocuments: 1000, |
| 71 | logger: logrus.New(), |
| 72 | } |
| 73 | |
| 74 | fakeConfig := fakeClassConfig{ |
| 75 | classConfig: map[string]any{ |
| 76 | "model": testModel, |
| 77 | }, |
| 78 | } |
| 79 | |
| 80 | result, err := client.Rank(context.Background(), testQuery, []string{"doc1", "doc2", "doc3"}, fakeConfig) |
| 81 | |
| 82 | require.NoError(t, err) |
| 83 | assert.Equal(t, testQuery, result.Query) |
| 84 | assert.Len(t, result.DocumentScores, 3) |
| 85 | assert.Equal(t, "doc1", result.DocumentScores[0].Document) |
| 86 | assert.Equal(t, 0.9, result.DocumentScores[0].Score) |
| 87 | } |
| 88 | |
| 89 | func TestClientMetaInfo(t *testing.T) { |
| 90 | client := &client{} |
nothing calls this directly
no test coverage detected
searching dependent graphs…