ai-stream-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.11 • Public • Published

AI Stream SDK

AI Stream SDK is a plugin that can quickly implement AI API data streams. It supports various model API forwarding, allowing you to quickly build your API forwarding service.

Features

  • Data flow transmission
  • Provide real-time monitoring of data stream in each stage
  • Future support for calculating token thresholds for model responses

Installation

pnpm add ai-stream-sdk

View the full documentation and examples on ai-stream-sdk.vercel.app.

Usage

import { OpenAIStream } from 'ai-stream-sdk'
import OpenAI from 'openai'

const openai = new OpenAI({
  apiKey: 'sk-*****',
})

export const runtime = 'edge'

export async function POST(request: Request) {
  const response = await openai.chat.completions.create({
    model: 'gpt-3.5-turbo',
    messages: [{ role: 'user', content: 'Say this is a test' }],
    stream: true,
  })

  const stream = OpenAIStream(response, {
    onStart: () => {
      console.log('onStart')
    },
    onCompletion: (completion) => {
      console.log(completion, 'completion')
    },
  })

  return new Response(stream)
}

Readme

Keywords

none

Package Sidebar

Install

npm i ai-stream-sdk

Weekly Downloads

0

Version

0.0.11

License

MIT

Unpacked Size

28 kB

Total Files

34

Last publish

Collaborators

  • liushuxiang1993