MCPcopy Create free account
hub / github.com/abi/screenshot-to-code / truncate_data_strings

Function truncate_data_strings

backend/utils.py:172–191  ·  view source on GitHub ↗
(data: List[ChatCompletionMessageParam])

Source from the content-addressed store, hash-verified

170
171
172def 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

Callers 1

pprint_promptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected