diff --git a/apps/recommendation/api/src/huggy/core/model_selection/__init__.py b/apps/recommendation/api/src/huggy/core/model_selection/__init__.py index ba40717a..f87d991c 100644 --- a/apps/recommendation/api/src/huggy/core/model_selection/__init__.py +++ b/apps/recommendation/api/src/huggy/core/model_selection/__init__.py @@ -22,10 +22,12 @@ from huggy.schemas.user import UserContext from huggy.schemas.utils import parse_input from huggy.utils.env_vars import ( - DEFAULT_RECO_MODEL, DEFAULT_RECO_MODEL_DESCRIPTION, DEFAULT_SIMILAR_OFFER_DESCRIPTION, - DEFAULT_SIMILAR_OFFER_MODEL, + RECO_MODEL_CONTEXT, + SIMILAR_OFFER_MODEL_CONTEXT, + VERSION_B_RECO_MODEL_DESCRIPTION, + VERSION_B_SIMILAR_OFFER_DESCRIPTION, ) from pydantic import ValidationError @@ -55,7 +57,7 @@ ), "version_b": RecoModelConfigurationInput( name="version_b", - description="""Configuration Ranking Version B.""", + description=VERSION_B_RECO_MODEL_DESCRIPTION, diversification_params=DiversificationParamsInput( diversication_type=DiversificationChoices.ON, ), @@ -187,7 +189,7 @@ ), "version_b": SimilarModelConfigurationInput( name="version_b", - description="""Similar offers (ranking version b).""", + description=VERSION_B_SIMILAR_OFFER_DESCRIPTION, diversification_params=DiversificationParamsInput( diversication_type=DiversificationChoices.OFF, ), @@ -240,7 +242,7 @@ def select_reco_model_params(model_endpoint: str, user: UserContext) -> ForkOut: model_fork = model_endpoint.custom_configuration.generate() else: if model_name not in list(RECOMMENDATION_ENDPOINTS.keys()): - model_name = DEFAULT_RECO_MODEL + model_name = RECO_MODEL_CONTEXT model_fork = RECOMMENDATION_ENDPOINTS[model_name].generate() return model_fork.get_user_status(user=user, model_origin=model_name) @@ -259,7 +261,7 @@ def select_sim_model_params( model_fork = model_endpoint.custom_configuration.generate() else: if model_name not in list(SIMILAR_OFFER_ENDPOINTS.keys()): - model_name = DEFAULT_SIMILAR_OFFER_MODEL + model_name = SIMILAR_OFFER_MODEL_CONTEXT model_fork = SIMILAR_OFFER_ENDPOINTS[model_name].generate() return model_fork.get_offer_status( offer=offer, offers=offers, model_origin=model_name diff --git a/apps/recommendation/api/src/huggy/crud/recommendable_offer.py b/apps/recommendation/api/src/huggy/crud/recommendable_offer.py index a2310f6e..c8167014 100644 --- a/apps/recommendation/api/src/huggy/crud/recommendable_offer.py +++ b/apps/recommendation/api/src/huggy/crud/recommendable_offer.py @@ -15,9 +15,8 @@ class RecommendableOffer: async def is_geolocated(self, user: UserContext, offer: o.Offer) -> bool: if user is not None and user.is_geolocated: return True - if offer is not None and offer.is_geolocated: - return True - return False + else: + return bool(offer is not None and offer.is_geolocated) async def get_nearest_offers( self, diff --git a/apps/recommendation/api/src/huggy/utils/env_vars.py b/apps/recommendation/api/src/huggy/utils/env_vars.py index 8b5249ac..4d6f93fa 100644 --- a/apps/recommendation/api/src/huggy/utils/env_vars.py +++ b/apps/recommendation/api/src/huggy/utils/env_vars.py @@ -41,16 +41,23 @@ http_request_context = contextvars.ContextVar("http_request_context", default={}) # config -DEFAULT_SIMILAR_OFFER_MODEL = os.environ.get("DEFAULT_SIMILAR_OFFER_MODEL", "default") +SIMILAR_OFFER_MODEL_CONTEXT = os.environ.get("SIMILAR_OFFER_MODEL_CONTEXT", "default") +RECO_MODEL_CONTEXT = os.environ.get("RECO_MODEL_CONTEXT", "default") + DEFAULT_SIMILAR_OFFER_DESCRIPTION = os.environ.get( "DEFAULT_SIMILAR_OFFER_DESCRIPTION", "Similar Offer Configuration (default)" ) -DEFAULT_RECO_MODEL = os.environ.get("DEFAULT_RECO_MODEL", "default") DEFAULT_RECO_MODEL_DESCRIPTION = os.environ.get( "DEFAULT_RECO_MODEL_DESCRIPTION", "Recommendation Configuration (default)" ) +VERSION_B_RECO_MODEL_DESCRIPTION = os.environ.get( + "VERSION_B_RECO_MODEL_DESCRIPTION", "Recommendation Configuration (version B)" +) +VERSION_B_SIMILAR_OFFER_DESCRIPTION = os.environ.get( + "VERSION_B_SIMILAR_OFFER_DESCRIPTION", "Similar Offer Configuration (version B)" +) # endpoints RANKING_VERSION_B_ENDPOINT_NAME = os.environ.get( "RANKING_VERSION_B_ENDPOINT_NAME",