Extract and format user history and preference
(self, row_data)
| 1555 | return semantic_ids |
| 1556 | |
| 1557 | def get_history(self, row_data): |
| 1558 | """Extract and format user history and preference""" |
| 1559 | # Get input history item IDs (all but last item) and convert to semantic IDs |
| 1560 | input_history_ids = row_data['input_history'] |
| 1561 | history_semantic_ids = self._convert_to_semantic_ids(input_history_ids) |
| 1562 | |
| 1563 | # Format semantic IDs as a comma-separated string |
| 1564 | history_str = ", ".join(history_semantic_ids) |
| 1565 | |
| 1566 | # Get user preference |
| 1567 | user_preference = row_data['user_preference'] |
| 1568 | |
| 1569 | # Get target item semantic ID |
| 1570 | target_item_id = row_data['target_item_id'] |
| 1571 | target_semantic_ids = self._convert_to_semantic_ids([target_item_id]) |
| 1572 | target_sid = target_semantic_ids[0] if target_semantic_ids else str(target_item_id) |
| 1573 | |
| 1574 | result = { |
| 1575 | "input": f"The user has interacted with items {history_str} in chronological order. Can you analyze the user's preferences and predict the next item?", |
| 1576 | "output": f"### Reasoning:\n{user_preference}\n### Response:\n{target_sid}", |
| 1577 | "history_semantic_ids": history_semantic_ids, |
| 1578 | "user_preference": user_preference, |
| 1579 | "target_sid": target_sid |
| 1580 | } |
| 1581 | # print(result) |
| 1582 | return result |
| 1583 | |
| 1584 | def pre(self, idx): |
| 1585 | instruction = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request. |
no test coverage detected