Generating
Text
Generates text for a given prompt.
npm i @xsai/generate-textExamples
Basic
import { } from '@xsai/generate-text'
import { } from 'node:process'
const { } = await ({
: .!,
: 'https://api.openai.com/v1/',
: [
{
: 'You\'re a helpful assistant.',
: 'system'
},
{
: 'Why is the sky blue?',
: 'user'
}
],
: 'gpt-4o',
})Image input
xsAI has no way of knowing if your model supports multi-modal, so please check before using it.
import { } from '@xsai/generate-text'
import { } from 'node:process'
const { } = await ({
: .!,
: '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/generate-text'
import { } from 'node:buffer'
import { } from 'node:process'
const = await ('https://cdn.openai.com/API/docs/audio/alloy.wav')
.( => .())
.( => .().('base64'))
const { } = await ({
: .!,
: 'https://api.openai.com/v1/',
: [{
: 'user',
: [
{ : 'text', : 'What is in this recording?' },
{ : 'input_audio', : { , : 'wav' }}
],
}],
: 'gpt-4o-audio-preview',
: ['text', 'audio'],
})