recommendationservice: exclude input ids
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
289bd4db13
commit
9634693f37
1 changed files with 8 additions and 4 deletions
|
@ -12,13 +12,17 @@ class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
|||
|
||||
# fetch list of products from product catalog stub
|
||||
cat_response = stub.ListProducts(demo_pb2.Empty())
|
||||
num_prodcuts = len(cat_response.products)
|
||||
num_return = min(max_responses, num_prodcuts)
|
||||
|
||||
product_ids = [x.id for x in cat_response.products]
|
||||
filtered_products = list(set(product_ids)-set(request.product_ids))
|
||||
|
||||
num_products = len(filtered_products)
|
||||
num_return = min(max_responses, num_products)
|
||||
|
||||
# sample list of indicies to return
|
||||
indices = random.sample(range(num_prodcuts), num_return)
|
||||
indices = random.sample(range(num_products), num_return)
|
||||
# fetch product ids from indices
|
||||
prod_list = [cat_response.products[i].id for i in indices]
|
||||
prod_list = [filtered_products[i] for i in indices]
|
||||
print("handling request: {}".format(prod_list))
|
||||
|
||||
# build and return response
|
||||
|
|
Loading…
Reference in a new issue