Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (ai/core): apply transform before callbacks and resolvables #4098

Merged
merged 45 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
59aece4
t1
lgrammel Dec 16, 2024
4b428c4
todo
lgrammel Dec 16, 2024
fdfaec3
impl
lgrammel Dec 16, 2024
720e855
t2
lgrammel Dec 16, 2024
9f32553
4
lgrammel Dec 16, 2024
4f7fa1b
warnings
lgrammel Dec 16, 2024
d30e3e1
refa
lgrammel Dec 16, 2024
323e041
t
lgrammel Dec 16, 2024
e1c4487
usage
lgrammel Dec 16, 2024
c973b23
finish reason
lgrammel Dec 16, 2024
6dfe091
note
lgrammel Dec 16, 2024
ca613ca
refa
lgrammel Dec 16, 2024
4bd2d4d
re
lgrammel Dec 16, 2024
89cc12d
ref
lgrammel Dec 16, 2024
4d6d04d
re
lgrammel Dec 16, 2024
7df45b5
tool calls
lgrammel Dec 16, 2024
16a7480
ref
lgrammel Dec 16, 2024
0174519
refa
lgrammel Dec 16, 2024
5bd8881
ref
lgrammel Dec 16, 2024
fa31055
ref
lgrammel Dec 16, 2024
57e6c20
ref
lgrammel Dec 16, 2024
528f7ae
ref
lgrammel Dec 16, 2024
6e69e77
resulst
lgrammel Dec 16, 2024
d147981
steps
lgrammel Dec 16, 2024
3f3b013
request
lgrammel Dec 16, 2024
d14ae9e
simpler
lgrammel Dec 16, 2024
0e72b9b
provdier metadata
lgrammel Dec 16, 2024
58317fc
warnings
lgrammel Dec 16, 2024
7f1148d
ref
lgrammel Dec 16, 2024
272a0a0
move onfinish
lgrammel Dec 16, 2024
72a77bd
rm
lgrammel Dec 16, 2024
d583b40
imports
lgrammel Dec 16, 2024
8683c53
add usage
lgrammel Dec 16, 2024
2daa8ac
ref
lgrammel Dec 16, 2024
f28c5a2
ref
lgrammel Dec 16, 2024
643eea4
1
lgrammel Dec 16, 2024
2e99b9e
ref
lgrammel Dec 16, 2024
043a6ae
telemtry
lgrammel Dec 16, 2024
35cbc47
x
lgrammel Dec 16, 2024
897df32
x
lgrammel Dec 16, 2024
60dfec3
Merge remote-tracking branch 'origin/main' into lg/7pJxaFG
lgrammel Dec 17, 2024
a73c829
chang
lgrammel Dec 17, 2024
4fb65e4
ref
lgrammel Dec 17, 2024
e3e9153
guide
lgrammel Dec 17, 2024
2da048e
onchunk
lgrammel Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tricky-buckets-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

fix (ai/core): apply transform before callbacks and resolvables
5 changes: 5 additions & 0 deletions content/docs/03-ai-sdk-core/05-generating-text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ for await (const part of result.fullStream) {
You can use the `experimental_transform` option to transform the stream.
This is useful for e.g. filtering, changing, or smoothing the text stream.

The transformations are applied before the callbacks are invoked and the promises are resolved.
If you e.g. have a transformation that changes all text to uppercase, the `onFinish` callback will receive the transformed text.

#### Smoothing streams

The AI SDK Core provides a [`smoothStream` function](/docs/reference/ai-sdk-core/smooth-stream) that
can be used to smooth out text streaming.

Expand Down
61 changes: 55 additions & 6 deletions content/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1415,19 +1415,32 @@ To see `streamText` in action, check out [these examples](#examples).
],
},
{
name: 'isContinued',
type: 'boolean',
description:
'True when there will be a continuation step with a continuation text.',
name: 'request',
type: 'RequestMetadata',
isOptional: true,
description: 'Request metadata.',
properties: [
{
type: 'RequestMetadata',
parameters: [
{
name: 'body',
type: 'string',
description:
'Raw request HTTP body that was sent to the provider API as a string.',
},
],
},
],
},
{
name: 'response',
type: 'Response',
type: 'ResponseMetadata',
isOptional: true,
description: 'Response metadata.',
properties: [
{
type: 'Response',
type: 'ResponseMetadata',
parameters: [
{
name: 'id',
Expand All @@ -1447,10 +1460,34 @@ To see `streamText` in action, check out [these examples](#examples).
description:
'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
},
{
name: 'headers',
type: 'Record<string, string>',
description: 'The response headers.',
},
],
},
],
},
{
name: 'warnings',
type: 'Warning[] | undefined',
description:
'Warnings from the model provider (e.g. unsupported settings).',
},
{
name: 'experimental_providerMetadata',
type: 'Record<string,Record<string,JSONValue>> | undefined',
isOptional: true,
description:
'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
},
{
name: 'isContinued',
type: 'boolean',
description:
'True when there will be a continuation step with a continuation text.',
},
],
},
{
Expand Down Expand Up @@ -1521,10 +1558,22 @@ To see `streamText` in action, check out [these examples](#examples).
description:
'The timestamp of the response. The AI SDK uses the response timestamp from the provider response when available, and creates a timestamp otherwise.',
},
{
name: 'headers',
type: 'Record<string, string>',
description: 'The response headers.',
},
],
},
],
},
{
name: 'experimental_providerMetadata',
type: 'Record<string,Record<string,JSONValue>> | undefined',
isOptional: true,
description:
'Optional metadata from the provider. The outer key is the provider name. The inner values are the metadata. Details depend on the provider.',
},
],
},
],
Expand Down
Loading
Loading