0.0.3 • Published 8 months ago

@pkgai/fetch-sse v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@pkgai/fetch-sse

npm version npm downloads bundle size install size license

EventSource fetch 实现版

安装

# ✨ Auto-detect
npx nypm install @pkgai/fetch-sse

# npm
npm install @pkgai/fetch-sse

# yarn
yarn add @pkgai/fetch-sse

# pnpm
pnpm install @pkgai/fetch-sse

# bun
bun install @pkgai/fetch-sse

# deno
deno install @pkgai/fetch-sse

简单使用

import { fetch } from '@pkgai/fetch-sse'

const response = await fetch('https://openai-like/v1/chat/completions',{
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer {API_KEY}',
  },
  body: JSON.stringify({
    model: 'qwq-32b',
    messages: [
      {
        role: 'user',
        content: '9.9和9.11谁大',
      },
    ],
    stream: true,
    stream_options: {
      include_usage: true,
    },
  })
})

for await (const chunk of response) {
  console.log(chunk)
  // data: 
  console.log(chunk.data)
  // event:
  console.log(chunk.event)
}

贡献者

Published under the MIT license. Made by @Colourlessglow and community 💛


🤖 auto updated with automd

0.0.3

8 months ago