(namespace: str, recommender: str, user_id: str, item_ids: List[str], background: BackgroundTasks)
| 445 | ) |
| 446 | |
| 447 | def _rerank_items(namespace: str, recommender: str, user_id: str, item_ids: List[str], background: BackgroundTasks) -> Tuple[Response, Dict]: |
| 448 | rec_config = config.get_recommender_config(namespace, recommender, ACTION_RERANK_ITEMS) |
| 449 | if not rec_config: |
| 450 | raise ConfigError(HTTPStatus.NOT_FOUND, 'RecommenderNotConfigured', 'Recommender not configured for this namespace and recommender path') |
| 451 | |
| 452 | variation, experiment = evaluate_variations(rec_config, user_id, background) |
| 453 | context = resolve_context(variation) |
| 454 | |
| 455 | if variation.get('type') in ['personalize-campaign', 'personalize-recommender']: |
| 456 | arn = variation.get('arn') |
| 457 | filter_arn, filter_values = resolve_filter_parameters(variation, user_id) |
| 458 | |
| 459 | response = personalize_resolver.rerank_items( |
| 460 | variation_config = variation, |
| 461 | arn = arn, |
| 462 | user_id = user_id, |
| 463 | input_list = item_ids, |
| 464 | filter_arn = filter_arn, |
| 465 | filter_values = filter_values, |
| 466 | context = context, |
| 467 | include_metadata = try_decorate_items() |
| 468 | ) |
| 469 | |
| 470 | post_decorate_items(namespace, response) |
| 471 | elif variation.get('type') == 'sagemaker': |
| 472 | response = sagemaker_resolver.rerank_items( |
| 473 | recommender, |
| 474 | rec_config, |
| 475 | variation, |
| 476 | user_id = user_id, |
| 477 | input_list = item_ids, |
| 478 | context = context |
| 479 | ) |
| 480 | |
| 481 | post_decorate_items(namespace, response) |
| 482 | elif variation.get('type') == 'lambda': |
| 483 | response = lambda_resolver.rerank_items( |
| 484 | recommender, |
| 485 | rec_config, |
| 486 | variation, |
| 487 | user_id = user_id, |
| 488 | input_list = item_ids, |
| 489 | context = context |
| 490 | ) |
| 491 | |
| 492 | post_decorate_items(namespace, response) |
| 493 | elif variation.get('type') == 'http': |
| 494 | url = variation['url'].format(**app.current_event.query_string_parameters) |
| 495 | response = json.loads(urllib.request.urlopen(url).read()) |
| 496 | |
| 497 | if response and experiment: |
| 498 | response['matchedExperiment'] = experiment |
| 499 | |
| 500 | post_process_config = rec_config.get('responsePostProcessor') |
| 501 | if post_process_config: |
| 502 | response = post_processor.process_rerank_items(recommender, rec_config, variation, user_id, response) |
| 503 | |
| 504 | return response, variation |
no test coverage detected