2.0.0 • Published 12 months ago

stream-hooks v2.0.0

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

stream-hooks

Installation

with pnpm

$ pnpm add stream-hooks zod zod-stream

with npm

$ npm install stream-hooks zod zod-stream

with bun

$ bun add stream-hooks zod zod-stream

useJsonStream

  import { useJsonStream } from "stream-hooks"

  export function Test() {
    const { loading, startStream, stopStream, data } = useJsonStream({
      schema: z.object({
        content: z.string()
      }),
      onReceive: data => {
        console.log("incremental update to final response model", data)
      }
    })

  const submit = async () => {
    try {
      await startStream({
        url: "/api/ai/chat",
        method: "POST",
        body: {
          messages: [
            {
              content: "yo",
              role: "user"
            }
          ]
        }
      })
    } catch (e) {
      console.error(e)
    }
  }

    return (
      <div>
        {data.content}

        <button onClick={submit}>
          start
        </button>

        <button onClick={stopStream}>
          stop
        </button>
      </div>
    )
  }
2.0.0

12 months ago

1.0.4

1 year ago

1.0.0

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.1--alpha.1

1 year ago

0.0.1--alpha.0

2 years ago