Expand description
The two shapes a message’s content takes, read in one place.
An OpenAI message’s content is a string, or an array of parts in which
the text parts carry a text field beside parts that are not text
(image_url, …). VS Code’s LLM gateway sends the array form on every
message. Each stage that reads or rewrites message text has to handle
both, and until now each walked them inline where it needed them:
canonicalisation rewrote each shape’s text in place, and truncation
measured the string and skipped the array. The walk lives here so a stage
that handles one shape handles the other.
Everything here works on a raw serde_json::Value, never on a typed
message, because the callers forward the body they were given: a round
trip through a typed message re-serialises it, and the byte stability of
the forwarded prompt is what canonicalisation exists to protect.
Functions§
- append_
text - Append
texttocontentas a trailing piece of text, in either shape, and say whether it could be. - for_
each_ text_ mut - Apply
fto every piece of text incontent, in either shape, and say how many pieces it visited. - text_
len - The number of characters of text
contentcarries, in either shape. - text_
parts - The number of pieces of text
contentcarries: 1 for a string, one per text part for an array, 0 for anything else.