Skip to content

Commit

Permalink
fix batch predication signature
Browse files Browse the repository at this point in the history
  • Loading branch information
masonkmeyer committed Aug 26, 2022
1 parent a59040a commit 3ea9891
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions agify.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ func (client *Client) PredictWithCountry(name string, country string) (*Predicti
}

// BatchPredict returns the age probability for a list of names
func (client *Client) BatchPredict(names []string) (*[]Prediction, *RateLimit, error) {
func (client *Client) BatchPredict(names []string) ([]Prediction, *RateLimit, error) {
return client.BatchPredictWithCountry(names, "")
}

// BatchPredict returns the age probability for a list of names in a country
func (client *Client) BatchPredictWithCountry(names []string, country string) (*[]Prediction, *RateLimit, error) {
func (client *Client) BatchPredictWithCountry(names []string, country string) ([]Prediction, *RateLimit, error) {
url, _ := url.Parse(client.baseUrl)
values := url.Query()

Expand Down Expand Up @@ -166,7 +166,7 @@ func (client *Client) BatchPredictWithCountry(names []string, country string) (*
return nil, rateLimit, err
}

return &predictions, rateLimit, nil
return predictions, rateLimit, nil
}

// get makes the API request and returns the response body
Expand Down
17 changes: 17 additions & 0 deletions agify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,20 @@ func TestShouldOverrideDefaults(t *testing.T) {
_, _, err := client.Predict("michael")
assert.NotNil(t, err)
}

func TestShouldHandleBatchPrediction(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
names := r.URL.Query()["name[]"]
assert.NotNil(t, names)
assert.Len(t, names, 3)
w.Write([]byte(`[{"name":"michael","age":70,"count":233482},{"name":"matthew","age":36,"count":34742},{"name":"jane","age":36,"count":35010}]`))
}))
defer server.Close()

client := NewClient(WithUrl(server.URL))

result, _, err := client.BatchPredict([]string{"michael", "matthew", "jane"})
assert.Nil(t, err)
assert.Len(t, result, 3)
}

0 comments on commit 3ea9891

Please sign in to comment.