You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Backport: feat(ai): add convertDataPart option to convertToModelMessages (#9748)
This is an automated backport of #9720 to the release-v5.0 branch.
---------
Co-authored-by: Drew Foxall <drew_garratt@mckinsey.com>
Co-authored-by: Lars Grammel <lars.grammel@gmail.com>
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
feat(ai): add convertDataPart option to convertToModelMessages
6
+
7
+
Add optional convertDataPart callback for converting custom data parts (URLs, code files, etc.) to text or file parts that models can process. Fully type-safe using existing UIMessage generics.
'Optional configuration object. Provide tools to enable multi-modal tool responses.',
46
+
'Optional configuration object. Provide tools to enable multi-modal tool responses, and convertDataPart to transform custom data parts into model-compatible content.',
47
47
},
48
48
]}
49
49
/>
@@ -87,3 +87,144 @@ const result = streamText({
87
87
```
88
88
89
89
Tools can implement the optional `toModelOutput` method to transform their results into multi-modal content. The content is an array of content parts, where each part has a `type` (e.g., 'text', 'image') and corresponding data.
90
+
91
+
## Custom Data Part Conversion
92
+
93
+
The `convertToModelMessages` function supports converting custom data parts attached to user messages. This is useful when users need to include additional context (URLs, code files, JSON configs) with their messages.
94
+
95
+
### Basic Usage
96
+
97
+
By default, data parts in user messages are filtered out during conversion. To include them, provide a `convertDataPart` callback that transforms data parts into text or file parts that the model can understand:
0 commit comments