-
Notifications
You must be signed in to change notification settings - Fork 296
Closed
Labels
Description
Overview
This task involves implementing the logic that interacts with the backend to perform topic and content embedding capabilities within the recommendations adapter
Description and outcomes
- The
BackendRequestclass- Locate the class. It resides in
contentcuration/automation/utils/appnexus/base.py - The constructor accepts
headers: Request headersparams: Query parameters for the request.data: Request datajson: Request json.timeout: Max. time of responsekwargs: Additional keyword arguments.
- Add the following parameters to the constructor:
path: The endpoint path for the request.method: HTTP method for the request (e.g., GET, POST).
- Locate the class. It resides in
- Create new classes in
contentcuration/contentcuration/utils/recommendations.py.EmbedTopicsRequestandEmbedContentRequestthat inherit fromRecommendationsBackendRequest.RecommendationsBackendRequestinherits fromBackendRequest- Set
pathandmethodwith appropriate endpoint paths and methods- Embedding topics:
/embed-topics,POST - Embedding content:
/embed-content,POST
- Embedding topics:
- The
RecommendationsAdapterclass- Locate the class. It resides in
contentcuration/contentcuration/utils/recommendations.py. - Create new methods to embed topics and content
embed_topics(topics: Dict[str, Any]) -> EmbeddingsResponse: Embeds topics based on provided topic(s).embed_content(self, nodes: List[ContentNode]) -> EmbeddingsResponse: Embeds content based on provided list of content nodes.
- Inside
embed_topics:- Attempt a connection to the backend using
Backend.connect() - Use
EmbedTopicsRequestto construct a specific request object based on the providedtopic. For example;
embed_topics_request = EmbedTopicsRequest( headers={}, params={}, json=topics, )
- Return the request using
Backend.make_request().
return self.backend.make_request(embed_topics_request)
- Attempt a connection to the backend using
- Inside
embed_content:- Attempt a connection to the backend using
Backend.connect() - Create a new method
extract_content(node: ContentNode) -> Dict[str, Any]]that extracts content from the provided node (see assumptions and scope). - For each
node, extract required content, and finally build the requestjsonbody.resources = [] for node in nodes: resource = self.extract_content(node) resources.append(resource) body = { 'resources': resources, 'metadata': {} }
- Use
EmbedContentRequestto construct a specific request object based on the body. For example;
embed_content_request = EmbedContentRequest( headers={}, params={}, json=body )
- Return the request using
Backend.make_request().
return self.backend.make_request(embed_content_request)
- Attempt a connection to the backend using
- Locate the class. It resides in
- Error handling
- The
make_requestsmethod raises exceptions, based on categories implemented in Implement the core functionality for theconnectandmake_requestmethods of theBackendabstract class. #4447 - Implement the error handling based on the categorizations above. if necessary(See Error handling below)
- Return the
EmbeddingsResponsefor the raised exception.try: .... except Exception as e: return EmbeddingsResponse(e)
- The
Acceptance Criteria
- The
BackendRequestclass is updated with arguments(headers,params,json,data,timeout) necessary to make HTTP requests. Additionally,kwargshave been added. EmbedTopicsRequestandEmbedContentRequestclasses inherit fromRecommendationsBackendRequestand appropriatepaths andmethods are set.- The
RecommendationsAdapterclass has methodsembed_topicsandembed_contentthat:- Attempt a connection to the backend using
Backend.connect(). - Construct appropriate request objects (
EmbedTopicsRequestorEmbedContentRequest) based on the provided request data. - Call the
make_requestmethod with the constructed request objects.
- Attempt a connection to the backend using
- Error handling is implemented accordingly.
- Tests are written to verify correctness of added code
Assumptions and Dependencies
extract_contentmethod returns an empty dictionary.- Whereas some variable and method names already exist in the code, others are presented as suggestions. Feel free to adapt these names as necessary, for clarity.
- Is blocked
- Blocks
Scope
The scope of this task is limited to;
- Implementing the logic to embed topics and content
This task doesn’t include;
- Implementing the
extract_contentmethod logic.
Accessibility Requirements
NA
Resources
Reactions are currently unavailable