Skip to content

Commit 1ec5efa

Browse files
committed
additionalData for interactions, returnAbGroup for recommendation endpoints
1 parent 96c4baf commit 1ec5efa

28 files changed

+104
-42
lines changed

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Basic example
3535
from recombee_api_client.api_requests import AddPurchase, RecommendItemsToUser, Batch
3636
import random
3737
38-
client = RecombeeClient('--my-database-id--', '--my-secret-token--'')
38+
client = RecombeeClient('--my-database-id--', '--db-private-token--')
3939
4040
#Generate some random purchases of items by users
4141
PROBABILITY_PURCHASED = 0.1
@@ -77,7 +77,7 @@ Using property values
7777
NUM = 100
7878
PROBABILITY_PURCHASED = 0.1
7979
80-
client = RecombeeClient('--my-database-id--', '--my-secret-token--'')
80+
client = RecombeeClient('--my-database-id--', '--db-private-token--')
8181
8282
#Clear the entire database
8383
client.send(ResetDatabase())

recombee_api_client/api_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def send(self, request):
6363

6464
@staticmethod
6565
def __get_http_headers(additional_headers=None):
66-
headers = {'User-Agent': 'recombee-python-api-client/2.2.0'}
66+
headers = {'User-Agent': 'recombee-python-api-client/2.3.0'}
6767
if additional_headers:
6868
headers.update(additional_headers)
6969
return headers

recombee_api_client/api_requests/add_bookmark.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class AddBookmark(Request):
99
1010
"""
1111

12-
def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT, recomm_id=DEFAULT):
12+
def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT, recomm_id=DEFAULT, additional_data=DEFAULT):
1313
"""
1414
Required parameters:
1515
@param user_id: User who bookmarked the item
@@ -24,12 +24,15 @@ def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT,
2424
2525
@param recomm_id: If this bookmark is based on a recommendation request, `recommId` is the id of the clicked recommendation.
2626
27+
@param additional_data: A dictionary of additional data for the interaction.
28+
2729
"""
2830
self.user_id = user_id
2931
self.item_id = item_id
3032
self.timestamp = timestamp
3133
self.cascade_create = cascade_create
3234
self.recomm_id = recomm_id
35+
self.additional_data = additional_data
3336
self.timeout = 1000
3437
self.ensure_https = False
3538
self.method = 'post'
@@ -48,6 +51,8 @@ def get_body_parameters(self):
4851
p['cascadeCreate'] = self.cascade_create
4952
if self.recomm_id is not DEFAULT:
5053
p['recommId'] = self.recomm_id
54+
if self.additional_data is not DEFAULT:
55+
p['additionalData'] = self.additional_data
5156
return p
5257

5358
def get_query_parameters(self):

recombee_api_client/api_requests/add_cart_addition.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class AddCartAddition(Request):
99
1010
"""
1111

12-
def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT, amount=DEFAULT, price=DEFAULT, recomm_id=DEFAULT):
12+
def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT, amount=DEFAULT, price=DEFAULT, recomm_id=DEFAULT, additional_data=DEFAULT):
1313
"""
1414
Required parameters:
1515
@param user_id: User who added the item to the cart
@@ -28,6 +28,8 @@ def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT,
2828
2929
@param recomm_id: If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
3030
31+
@param additional_data: A dictionary of additional data for the interaction.
32+
3133
"""
3234
self.user_id = user_id
3335
self.item_id = item_id
@@ -36,6 +38,7 @@ def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT,
3638
self.amount = amount
3739
self.price = price
3840
self.recomm_id = recomm_id
41+
self.additional_data = additional_data
3942
self.timeout = 1000
4043
self.ensure_https = False
4144
self.method = 'post'
@@ -58,6 +61,8 @@ def get_body_parameters(self):
5861
p['price'] = self.price
5962
if self.recomm_id is not DEFAULT:
6063
p['recommId'] = self.recomm_id
64+
if self.additional_data is not DEFAULT:
65+
p['additionalData'] = self.additional_data
6166
return p
6267

6368
def get_query_parameters(self):

recombee_api_client/api_requests/add_detail_view.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class AddDetailView(Request):
99
1010
"""
1111

12-
def __init__(self, user_id, item_id, timestamp=DEFAULT, duration=DEFAULT, cascade_create=DEFAULT, recomm_id=DEFAULT):
12+
def __init__(self, user_id, item_id, timestamp=DEFAULT, duration=DEFAULT, cascade_create=DEFAULT, recomm_id=DEFAULT, additional_data=DEFAULT):
1313
"""
1414
Required parameters:
1515
@param user_id: User who viewed the item
@@ -26,13 +26,16 @@ def __init__(self, user_id, item_id, timestamp=DEFAULT, duration=DEFAULT, cascad
2626
2727
@param recomm_id: If this detail view is based on a recommendation request, `recommId` is the id of the clicked recommendation.
2828
29+
@param additional_data: A dictionary of additional data for the interaction.
30+
2931
"""
3032
self.user_id = user_id
3133
self.item_id = item_id
3234
self.timestamp = timestamp
3335
self.duration = duration
3436
self.cascade_create = cascade_create
3537
self.recomm_id = recomm_id
38+
self.additional_data = additional_data
3639
self.timeout = 1000
3740
self.ensure_https = False
3841
self.method = 'post'
@@ -53,6 +56,8 @@ def get_body_parameters(self):
5356
p['cascadeCreate'] = self.cascade_create
5457
if self.recomm_id is not DEFAULT:
5558
p['recommId'] = self.recomm_id
59+
if self.additional_data is not DEFAULT:
60+
p['additionalData'] = self.additional_data
5661
return p
5762

5863
def get_query_parameters(self):

recombee_api_client/api_requests/add_purchase.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class AddPurchase(Request):
99
1010
"""
1111

12-
def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT, amount=DEFAULT, price=DEFAULT, profit=DEFAULT, recomm_id=DEFAULT):
12+
def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT, amount=DEFAULT, price=DEFAULT, profit=DEFAULT, recomm_id=DEFAULT, additional_data=DEFAULT):
1313
"""
1414
Required parameters:
1515
@param user_id: User who purchased the item
@@ -30,6 +30,8 @@ def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT,
3030
3131
@param recomm_id: If this purchase is based on a recommendation request, `recommId` is the id of the clicked recommendation.
3232
33+
@param additional_data: A dictionary of additional data for the interaction.
34+
3335
"""
3436
self.user_id = user_id
3537
self.item_id = item_id
@@ -39,6 +41,7 @@ def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT,
3941
self.price = price
4042
self.profit = profit
4143
self.recomm_id = recomm_id
44+
self.additional_data = additional_data
4245
self.timeout = 1000
4346
self.ensure_https = False
4447
self.method = 'post'
@@ -63,6 +66,8 @@ def get_body_parameters(self):
6366
p['profit'] = self.profit
6467
if self.recomm_id is not DEFAULT:
6568
p['recommId'] = self.recomm_id
69+
if self.additional_data is not DEFAULT:
70+
p['additionalData'] = self.additional_data
6671
return p
6772

6873
def get_query_parameters(self):

recombee_api_client/api_requests/add_rating.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class AddRating(Request):
99
1010
"""
1111

12-
def __init__(self, user_id, item_id, rating, timestamp=DEFAULT, cascade_create=DEFAULT, recomm_id=DEFAULT):
12+
def __init__(self, user_id, item_id, rating, timestamp=DEFAULT, cascade_create=DEFAULT, recomm_id=DEFAULT, additional_data=DEFAULT):
1313
"""
1414
Required parameters:
1515
@param user_id: User who submitted the rating
@@ -26,13 +26,16 @@ def __init__(self, user_id, item_id, rating, timestamp=DEFAULT, cascade_create=D
2626
2727
@param recomm_id: If this rating is based on a recommendation request, `recommId` is the id of the clicked recommendation.
2828
29+
@param additional_data: A dictionary of additional data for the interaction.
30+
2931
"""
3032
self.user_id = user_id
3133
self.item_id = item_id
3234
self.rating = rating
3335
self.timestamp = timestamp
3436
self.cascade_create = cascade_create
3537
self.recomm_id = recomm_id
38+
self.additional_data = additional_data
3639
self.timeout = 1000
3740
self.ensure_https = False
3841
self.method = 'post'
@@ -52,6 +55,8 @@ def get_body_parameters(self):
5255
p['cascadeCreate'] = self.cascade_create
5356
if self.recomm_id is not DEFAULT:
5457
p['recommId'] = self.recomm_id
58+
if self.additional_data is not DEFAULT:
59+
p['additionalData'] = self.additional_data
5560
return p
5661

5762
def get_query_parameters(self):

recombee_api_client/api_requests/recommend_items_to_item.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ class RecommendItemsToItem(Request):
88
Recommends set of items that are somehow related to one given item, *X*. Typical scenario is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Recommend items to item request gives you Top-N such items, optionally taking the target user *A* into account.
99
1010
It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
11+
12+
The returned items are sorted by relevancy (first item being the most relevant).
1113
1214
"""
1315

14-
def __init__(self, item_id, target_user_id, count, user_impact=DEFAULT, filter=DEFAULT, booster=DEFAULT, cascade_create=DEFAULT, scenario=DEFAULT, return_properties=DEFAULT, included_properties=DEFAULT, diversity=DEFAULT, min_relevance=DEFAULT, rotation_rate=DEFAULT, rotation_time=DEFAULT, expert_settings=DEFAULT):
16+
def __init__(self, item_id, target_user_id, count, user_impact=DEFAULT, filter=DEFAULT, booster=DEFAULT, cascade_create=DEFAULT, scenario=DEFAULT, return_properties=DEFAULT, included_properties=DEFAULT, diversity=DEFAULT, min_relevance=DEFAULT, rotation_rate=DEFAULT, rotation_time=DEFAULT, expert_settings=DEFAULT, return_ab_group=DEFAULT):
1517
"""
1618
Required parameters:
1719
@param item_id: ID of the item for which the recommendations are to be generated.
@@ -175,6 +177,9 @@ def __init__(self, item_id, target_user_id, count, user_impact=DEFAULT, filter=D
175177
@param expert_settings: Dictionary of custom options.
176178
177179
180+
@param return_ab_group: If there is a custom AB-testing running, return name of group to which the request belongs.
181+
182+
178183
"""
179184
self.item_id = item_id
180185
self.target_user_id = target_user_id
@@ -191,6 +196,7 @@ def __init__(self, item_id, target_user_id, count, user_impact=DEFAULT, filter=D
191196
self.rotation_rate = rotation_rate
192197
self.rotation_time = rotation_time
193198
self.expert_settings = expert_settings
199+
self.return_ab_group = return_ab_group
194200
self.timeout = 3000
195201
self.ensure_https = False
196202
self.method = 'post'
@@ -227,6 +233,8 @@ def get_body_parameters(self):
227233
p['rotationTime'] = self.rotation_time
228234
if self.expert_settings is not DEFAULT:
229235
p['expertSettings'] = self.expert_settings
236+
if self.return_ab_group is not DEFAULT:
237+
p['returnAbGroup'] = self.return_ab_group
230238
return p
231239

232240
def get_query_parameters(self):

recombee_api_client/api_requests/recommend_items_to_user.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ class RecommendItemsToUser(Request):
88
Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user.
99
1010
It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
11+
12+
The returned items are sorted by relevancy (first item being the most relevant).
1113
1214
"""
1315

14-
def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_create=DEFAULT, scenario=DEFAULT, return_properties=DEFAULT, included_properties=DEFAULT, diversity=DEFAULT, min_relevance=DEFAULT, rotation_rate=DEFAULT, rotation_time=DEFAULT, expert_settings=DEFAULT):
16+
def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_create=DEFAULT, scenario=DEFAULT, return_properties=DEFAULT, included_properties=DEFAULT, diversity=DEFAULT, min_relevance=DEFAULT, rotation_rate=DEFAULT, rotation_time=DEFAULT, expert_settings=DEFAULT, return_ab_group=DEFAULT):
1517
"""
1618
Required parameters:
1719
@param user_id: ID of the user for which personalized recommendations are to be generated.
@@ -141,6 +143,9 @@ def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
141143
@param expert_settings: Dictionary of custom options.
142144
143145
146+
@param return_ab_group: If there is a custom AB-testing running, return name of group to which the request belongs.
147+
148+
144149
"""
145150
self.user_id = user_id
146151
self.count = count
@@ -155,6 +160,7 @@ def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
155160
self.rotation_rate = rotation_rate
156161
self.rotation_time = rotation_time
157162
self.expert_settings = expert_settings
163+
self.return_ab_group = return_ab_group
158164
self.timeout = 3000
159165
self.ensure_https = False
160166
self.method = 'post'
@@ -188,6 +194,8 @@ def get_body_parameters(self):
188194
p['rotationTime'] = self.rotation_time
189195
if self.expert_settings is not DEFAULT:
190196
p['expertSettings'] = self.expert_settings
197+
if self.return_ab_group is not DEFAULT:
198+
p['returnAbGroup'] = self.return_ab_group
191199
return p
192200

193201
def get_query_parameters(self):

recombee_api_client/api_requests/recommend_users_to_item.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ class RecommendUsersToItem(Request):
88
Recommend users that are likely to be interested in a given item.
99
1010
It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
11+
12+
The returned users are sorted by predicted interest in the item (first user being the most interested).
1113
1214
"""
1315

14-
def __init__(self, item_id, count, filter=DEFAULT, booster=DEFAULT, cascade_create=DEFAULT, scenario=DEFAULT, return_properties=DEFAULT, included_properties=DEFAULT, diversity=DEFAULT, expert_settings=DEFAULT):
16+
def __init__(self, item_id, count, filter=DEFAULT, booster=DEFAULT, cascade_create=DEFAULT, scenario=DEFAULT, return_properties=DEFAULT, included_properties=DEFAULT, diversity=DEFAULT, expert_settings=DEFAULT, return_ab_group=DEFAULT):
1517
"""
1618
Required parameters:
1719
@param item_id: ID of the item for which the recommendations are to be generated.
@@ -120,6 +122,9 @@ def __init__(self, item_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
120122
@param expert_settings: Dictionary of custom options.
121123
122124
125+
@param return_ab_group: If there is a custom AB-testing running, return name of group to which the request belongs.
126+
127+
123128
"""
124129
self.item_id = item_id
125130
self.count = count
@@ -131,6 +136,7 @@ def __init__(self, item_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
131136
self.included_properties = included_properties
132137
self.diversity = diversity
133138
self.expert_settings = expert_settings
139+
self.return_ab_group = return_ab_group
134140
self.timeout = 50000
135141
self.ensure_https = False
136142
self.method = 'post'
@@ -158,6 +164,8 @@ def get_body_parameters(self):
158164
p['diversity'] = self.diversity
159165
if self.expert_settings is not DEFAULT:
160166
p['expertSettings'] = self.expert_settings
167+
if self.return_ab_group is not DEFAULT:
168+
p['returnAbGroup'] = self.return_ab_group
161169
return p
162170

163171
def get_query_parameters(self):

recombee_api_client/api_requests/recommend_users_to_user.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ class RecommendUsersToUser(Request):
88
Get similar users as some given user, based on the user's past interactions (purchases, ratings, etc.) and values of properties.
99
1010
It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
11+
12+
The returned users are sorted by similarity (first user being the most similar).
1113
1214
"""
1315

14-
def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_create=DEFAULT, scenario=DEFAULT, return_properties=DEFAULT, included_properties=DEFAULT, diversity=DEFAULT, min_relevance=DEFAULT, rotation_rate=DEFAULT, rotation_time=DEFAULT, expert_settings=DEFAULT):
16+
def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_create=DEFAULT, scenario=DEFAULT, return_properties=DEFAULT, included_properties=DEFAULT, diversity=DEFAULT, min_relevance=DEFAULT, rotation_rate=DEFAULT, rotation_time=DEFAULT, expert_settings=DEFAULT, return_ab_group=DEFAULT):
1517
"""
1618
Required parameters:
1719
@param user_id: User to which we find similar users
@@ -129,6 +131,9 @@ def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
129131
@param expert_settings: Dictionary of custom options.
130132
131133
134+
@param return_ab_group: If there is a custom AB-testing running, return name of group to which the request belongs.
135+
136+
132137
"""
133138
self.user_id = user_id
134139
self.count = count
@@ -143,6 +148,7 @@ def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_crea
143148
self.rotation_rate = rotation_rate
144149
self.rotation_time = rotation_time
145150
self.expert_settings = expert_settings
151+
self.return_ab_group = return_ab_group
146152
self.timeout = 50000
147153
self.ensure_https = False
148154
self.method = 'post'
@@ -176,6 +182,8 @@ def get_body_parameters(self):
176182
p['rotationTime'] = self.rotation_time
177183
if self.expert_settings is not DEFAULT:
178184
p['expertSettings'] = self.expert_settings
185+
if self.return_ab_group is not DEFAULT:
186+
p['returnAbGroup'] = self.return_ab_group
179187
return p
180188

181189
def get_query_parameters(self):

recombee_api_client/api_requests/set_view_portion.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SetViewPortion(Request):
1010
1111
"""
1212

13-
def __init__(self, user_id, item_id, portion, session_id=DEFAULT, timestamp=DEFAULT, cascade_create=DEFAULT, recomm_id=DEFAULT):
13+
def __init__(self, user_id, item_id, portion, session_id=DEFAULT, timestamp=DEFAULT, cascade_create=DEFAULT, recomm_id=DEFAULT, additional_data=DEFAULT):
1414
"""
1515
Required parameters:
1616
@param user_id: User who viewed a portion of the item
@@ -29,6 +29,8 @@ def __init__(self, user_id, item_id, portion, session_id=DEFAULT, timestamp=DEFA
2929
3030
@param recomm_id: If this view portion is based on a recommendation request, `recommId` is the id of the clicked recommendation.
3131
32+
@param additional_data: A dictionary of additional data for the interaction.
33+
3234
"""
3335
self.user_id = user_id
3436
self.item_id = item_id
@@ -37,6 +39,7 @@ def __init__(self, user_id, item_id, portion, session_id=DEFAULT, timestamp=DEFA
3739
self.timestamp = timestamp
3840
self.cascade_create = cascade_create
3941
self.recomm_id = recomm_id
42+
self.additional_data = additional_data
4043
self.timeout = 1000
4144
self.ensure_https = False
4245
self.method = 'post'
@@ -58,6 +61,8 @@ def get_body_parameters(self):
5861
p['cascadeCreate'] = self.cascade_create
5962
if self.recomm_id is not DEFAULT:
6063
p['recommId'] = self.recomm_id
64+
if self.additional_data is not DEFAULT:
65+
p['additionalData'] = self.additional_data
6166
return p
6267

6368
def get_query_parameters(self):

0 commit comments

Comments
 (0)