xsfetch
extra-small Fetch API with auto retry.
npm i xsfetch
Usage
createFetch
import { createFetch } from 'xsfetch'
const fetch = createFetch({
retry: 3,
retryDelay: 1000,
})
createFetch with generateText
import { generateText } from '@xsai/generate-text'
import { env } from 'node:process'
import { createFetch } from 'xsfetch'
const fetch = createFetch({
retry: 3,
retryDelay: 1000,
})
const { text } = await generateText({
apiKey: env.OPENAI_API_KEY!,
baseURL: 'https://api.openai.com/v1/',
fetch,
messages: [
{
content: 'You\'re a helpful assistant.',
role: 'system'
},
{
content: 'Why is the sky blue?',
role: 'user'
}
],
model: 'gpt-4o',
})