xsAI v0.2 is now available! Read Announcement
xsAI0.3.0-beta.5
Generating

Text

Generates text for a given prompt.

install sizeminified sizeminzipped size
npm i @xsai/generate-text

Examples

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'], 
})
Edit on GitHub

Last updated on

On this page