| 170 | |
| 171 | |
| 172 | def truncate_data_strings(data: List[ChatCompletionMessageParam]): # type: ignore |
| 173 | # Deep clone the data to avoid modifying the original object |
| 174 | cloned_data = copy.deepcopy(data) |
| 175 | |
| 176 | if isinstance(cloned_data, dict): |
| 177 | for key, value in cloned_data.items(): # type: ignore |
| 178 | # Recursively call the function if the value is a dictionary or a list |
| 179 | if isinstance(value, (dict, list)): |
| 180 | cloned_data[key] = truncate_data_strings(value) # type: ignore |
| 181 | # Truncate the string if it it's long and add ellipsis and length |
| 182 | elif isinstance(value, str): |
| 183 | cloned_data[key] = value[:40] # type: ignore |
| 184 | if len(value) > 40: |
| 185 | cloned_data[key] += "..." + f" ({len(value)} chars)" # type: ignore |
| 186 | |
| 187 | elif isinstance(cloned_data, list): # type: ignore |
| 188 | # Process each item in the list |
| 189 | cloned_data = [truncate_data_strings(item) for item in cloned_data] # type: ignore |
| 190 | |
| 191 | return cloned_data # type: ignore |