Streaming
Text
Streams text from a given prompt.
npm i @xsai/stream-textExamples
Basic
import { } from '@xsai/stream-text'
import { } from 'node:process'
const { } = ({
: .!,
: 'https://api.openai.com/v1/',
: [
{
: 'You are a helpful assistant.',
: 'system',
},
{
: 'This is a test, so please answer'
+ '\'The quick brown fox jumps over the lazy dog.\''
+ 'and nothing else.',
: 'user',
},
],
: 'gpt-4o',
})
const : string[] = []
for await (const of ) {
.()
}
// "The quick brown fox jumps over the lazy dog."
.()Image input
xsAI has no way of knowing if your model supports multi-modal, so please check before using it.
import { } from '@xsai/stream-text'
import { } from 'node:process'
const { } = ({
: .!,
: 'https://api.openai.com/v1/',
: [{
: 'user',
: [
{ : 'text', : 'What\'s in this image?' },
{
: 'image_url',
: {
: 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg',
},
},
],
}],
: 'gpt-4o',
})Audio input
xsAI has no way of knowing if your model supports multi-modal, so please check before using it.
import { } from '@xsai/stream-text'
import { } from 'node:buffer'
import { } from 'node:process'
const = await ('https://cdn.openai.com/API/docs/audio/alloy.wav')
.( => .())
.( => .().('base64'))
const { } = ({
: .!,
: 'https://api.openai.com/v1/',
: [{
: 'user',
: [
{ : 'text', : 'What is in this recording?' },
{ : 'input_audio', : { , : 'wav' }}
],
}],
: 'gpt-4o-audio-preview',
: ['text', 'audio'],
})