Skip to content

Commit 5428a0d

Browse files
vercel-ai-sdk[bot]mhodgsonlgrammel
authored
Backport: feat(provider/openai): Add Code Interpreter input streaming support (#9004)
This is an automated backport of #8973 to the release-v5.0 branch. Co-authored-by: Matt Hodgson <matthodgson@mac.com> Co-authored-by: Lars Grammel <lars.grammel@gmail.com>
1 parent 99104af commit 5428a0d

File tree

4 files changed

+952
-50
lines changed

4 files changed

+952
-50
lines changed

.changeset/proud-rockets-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ai-sdk/openai': patch
3+
---
4+
5+
The built in Code Interpreter tool input code is streamed in `tool-input-<start/delta/end>` chunks.

examples/next-openai/component/openai-code-interpreter-view.tsx

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,42 @@ export default function CodeInterpreterView({
66
}: {
77
invocation: UIToolInvocation<ReturnType<typeof openai.tools.codeInterpreter>>;
88
}) {
9-
switch (invocation.state) {
10-
case 'output-available':
11-
return (
12-
<div className="mb-2 bg-gray-900 rounded-xl border border-gray-600 shadow-lg">
13-
<div className="px-6 py-3 bg-gray-800 rounded-t-xl border-b border-gray-700">
14-
<div className="overflow-hidden tracking-wide text-gray-500 whitespace-nowrap text-xxs font-small text-ellipsis">
15-
{invocation.input.containerId}
16-
</div>
17-
</div>
9+
return (
10+
<div className="mb-2 bg-gray-900 rounded-xl border border-gray-600 shadow-lg">
11+
<div className="px-6 py-3 bg-gray-800 rounded-t-xl border-b border-gray-700">
12+
<div className="overflow-hidden tracking-wide text-gray-500 whitespace-nowrap text-xxs font-small text-ellipsis">
13+
{invocation.input?.containerId}
14+
</div>
15+
</div>
1816

19-
<div className="p-6">
20-
<div className="mb-3">
21-
<div className="mb-2 text-sm font-medium text-blue-400">
22-
Code:
23-
</div>
24-
<pre className="overflow-x-auto p-4 text-sm text-gray-100 whitespace-pre-wrap bg-black rounded-lg">
25-
{invocation.input.code}
26-
</pre>
27-
</div>
17+
<div className="p-6">
18+
<div className="mb-3">
19+
<div className="mb-2 text-sm font-medium text-blue-400">Code:</div>
20+
<pre className="overflow-x-auto p-4 text-sm text-gray-100 whitespace-pre-wrap bg-black rounded-lg">
21+
{invocation.input?.code}
22+
</pre>
23+
</div>
2824

29-
<div className="mb-3">
30-
<div className="mb-2 text-sm font-medium text-yellow-400">
31-
Output:
32-
</div>
33-
<div className="space-y-2">
34-
{invocation.output.outputs?.map((output, index) => (
35-
<div key={index} className="p-3 bg-black rounded-lg">
36-
{output.type === 'logs' && (
37-
<div className="font-mono text-sm text-green-300">
38-
<span className="whitespace-pre-wrap">
39-
{output.logs}
40-
</span>
41-
</div>
42-
)}
43-
{output.type === 'image' && <img src={output.url} />}
44-
</div>
45-
))}
46-
</div>
25+
{invocation.state === 'output-available' && (
26+
<div className="mb-3">
27+
<div className="mb-2 text-sm font-medium text-yellow-400">
28+
Output:
29+
</div>
30+
<div className="space-y-2">
31+
{invocation.output.outputs?.map((output, index) => (
32+
<div key={index} className="p-3 bg-black rounded-lg">
33+
{output.type === 'logs' && (
34+
<div className="font-mono text-sm text-green-300">
35+
<span className="whitespace-pre-wrap">{output.logs}</span>
36+
</div>
37+
)}
38+
{output.type === 'image' && <img src={output.url} />}
39+
</div>
40+
))}
4741
</div>
4842
</div>
49-
</div>
50-
);
51-
}
43+
)}
44+
</div>
45+
</div>
46+
);
5247
}

0 commit comments

Comments
 (0)