Process description according to the requirements: 1. If description is empty, use title 2. If description is a list, select the longest one 3. If the longest in list is also empty, use title Args: description: The description field from
(self, description, title)
| 1179 | self.get_inputs() |
| 1180 | |
| 1181 | def _process_description(self, description, title): |
| 1182 | """ |
| 1183 | Process description according to the requirements: |
| 1184 | 1. If description is empty, use title |
| 1185 | 2. If description is a list, select the longest one |
| 1186 | 3. If the longest in list is also empty, use title |
| 1187 | |
| 1188 | Args: |
| 1189 | description: The description field from item_feat |
| 1190 | title: The title field from item_feat |
| 1191 | |
| 1192 | Returns: |
| 1193 | str: Processed description |
| 1194 | """ |
| 1195 | # Check if description is empty or None |
| 1196 | if not description or description == '': |
| 1197 | return title |
| 1198 | |
| 1199 | # Check if description is a list (either actual list or string representation) |
| 1200 | if isinstance(description, list): |
| 1201 | # It's already a list |
| 1202 | desc_list = description |
| 1203 | elif isinstance(description, str) and description.startswith('[') and description.endswith(']'): |
| 1204 | try: |
| 1205 | # Try to parse string representation of list |
| 1206 | desc_list = eval(description) |
| 1207 | except: |
| 1208 | # If parsing fails, treat as regular string |
| 1209 | return description if description.strip() else title |
| 1210 | else: |
| 1211 | # Regular string description |
| 1212 | return description if description.strip() else title |
| 1213 | |
| 1214 | # If we have a list, find the longest non-empty item |
| 1215 | if desc_list: |
| 1216 | # Filter out empty strings and find the longest |
| 1217 | non_empty_descriptions = [desc for desc in desc_list if desc and desc.strip()] |
| 1218 | if non_empty_descriptions: |
| 1219 | # Return the longest description |
| 1220 | longest_desc = max(non_empty_descriptions, key=len) |
| 1221 | return longest_desc |
| 1222 | else: |
| 1223 | # All descriptions in list are empty, use title |
| 1224 | return title |
| 1225 | else: |
| 1226 | # Empty list, use title |
| 1227 | return title |
| 1228 | |
| 1229 | def generate_prompt_title(self, history): |
| 1230 | return f"The user has sequentially interacted with items {history}. Can you recommend the next item for him? Tell me the title of the item" |