Class: BraintrustStream
A Braintrust stream. This is a wrapper around a ReadableStream of BraintrustStreamChunk
,
with some utility methods to make them easy to log and convert into various formats.
Constructors
constructor
• new BraintrustStream(baseStream
): BraintrustStream
Parameters
Name | Type |
---|---|
baseStream | ReadableStream <Uint8Array > |
Returns
• new BraintrustStream(stream
): BraintrustStream
Parameters
Name | Type |
---|---|
stream | ReadableStream <string > |
Returns
• new BraintrustStream(stream
): BraintrustStream
Parameters
Name | Type |
---|---|
stream | ReadableStream <BraintrustStreamChunk > |
Returns
Methods
copy
▸ copy(): BraintrustStream
Copy the stream. This returns a new stream that shares the same underlying
stream (via tee
). Since streams are consumed in Javascript, use copy()
if you
need to use the stream multiple times.
Returns
A new stream that you can independently consume.
finalValue
▸ finalValue(): Promise
<unknown
>
Get the final value of the stream. This will return a promise that resolves
when the stream is closed, and contains the final value of the stream. Multiple
calls to finalValue()
will return the same promise, so it is safe to call
this multiple times.
This function consumes the stream, so if you need to use the stream multiple
times, you should call copy()
first.
Returns
Promise
<unknown
>
A promise that resolves with the final value of the stream.
toReadableStream
▸ toReadableStream(): ReadableStream
<BraintrustStreamChunk
>
Get the underlying ReadableStream.
Returns
ReadableStream
<BraintrustStreamChunk
>
The underlying ReadableStream.