0.0.2 • Published 5 months ago

@yomo/viv v0.0.2

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
5 months ago

viv

AI Agent Toolkit with fast and meaningful streaming response

Installation

npm install @yomo/viv

Usage

import Viv from '@yomo/viv'

const client = new Viv({
  apiKey: 'API_KEY',
})

async function main() {
  const stream = await client.chat.completions.stream({
    message: [{ role: 'user', content: 'Say this is a test' }],
  })
  for await (const chunk of stream){
    console.log(chunk.type, chunk.data)
  }
}

main()

Chat Completion streaming helpers

This library also provides several conveniences for streaming chat completions, for example:

import Viv from '@yomo/viv'

const client = new Viv({
  apiKey: process.env.API_KEY,
})

async function main() {
  const stream = await client.chat.completions.stream({
    message: [{ role: 'user', content: 'Say this is a test' }],
  })
  stream.on('connect', () => {
    console.log('connected')
  })

  stream.on('reasoning', (reasoning) => {
    console.log('reasoning: ', reasoning)
  })

  stream.on('content', (content) => {
    console.log('content: ', content)
  })

  stream.on('finish', (finish) => {
    console.log('finish: ', finish)
  })

  stream.on('system', (system) => {
    console.log('system: ', system)
  })

  stream.on('usage', (usage) => {
    console.log('usage: ', usage)
  })

  stream.on('functionCall', (name, args) => {
    console.log('function_call: ', name, args)
  })

  stream.on('functionCallResult', (name, result) => {
    console.log('function_call_result: ', name, result)
  })

  stream.on('error', (error) => {
    console.error('error:', error)
  })

  stream.on('abort', () => {
    console.log('abort')
  })
}

main()

Retries

Certain errors will be automatically retried 2 times by default, >=500 Internal errors will all be retried by default

const client = new Viv({
  maxRetries: 0, // default is 2
})

Timeouts

Requests time out after 10 minutes by default. You can configure this with a timeout option:

const client = new Viv({
  timeout: 20 * 1000, // 20 seconds (default is 10 minutes)
})
0.0.2

5 months ago

0.0.1

5 months ago