Skip to content

Commit

Permalink
support get recommend with offset
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaoz committed Oct 12, 2022
1 parent e267bc0 commit 9dddd0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions gorse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ def list_feedbacks(self, feedback_type: str, user_id: str):
return r.json()
raise GorseException(r.status_code, r.text)

def get_recommend(self, user_id: str, category: str = "", n: int = 10) -> List[str]:
def get_recommend(self, user_id: str, category: str = "", n: int = 10, offset: int = 0, write_back_type: str = None,
write_back_delay: str = None) -> List[str]:
payload = {"n": n, "offset": offset}
if write_back_type:
payload["write-back-type"] = write_back_type
if write_back_delay:
payload["write-back-delay"] = write_back_delay
r = requests.get(
self.entry_point + "/api/recommend/%s/%s?n=%d" % (user_id, category, n),
self.entry_point + "/api/recommend/%s/%s" % (user_id, category),
params=payload,
headers={"X-API-Key": self.api_key},
)
if r.status_code == 200:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_gorse.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def test_recommend():
client = Gorse(GORSE_ENDPOINT, GORSE_API_KEY)
recommend = client.get_recommend('100')
assert recommend == ['3', '2', '1']
recommend = client.get_recommend("100", n=1, offset=1)
assert recommend == ["2"]


def test_neighbors():
Expand Down

0 comments on commit 9dddd0a

Please sign in to comment.