API Reference
zod-stream
offers various classes and functions to handle structured JSON streaming. Below is the detailed API reference.
ZodStream
import ZodStream from "zod-stream"
const zodstream = new ZodStream(config)
Constructor
constructor(config?: ClientConfig)
ClientConfig
Property | Type | Description | Default |
---|
debug | boolean | Enables debug mode for detailed logging. | false |
Methods
chatCompletionStream
chatCompletionStream<T extends z.AnyZodObject>(params: StructredStreamCompletionParams<T>): Promise<AsyncGenerator<Partial<z.infer<T>>, void, unknown>>
StructredStreamCompletionParams
Property | Type | Description |
---|
completionPromise | Function | A function that returns a promise resolving to a stream. |
data | any | Data to be sent in the stream request. |
response_model | ResponseModel<T> | The Zod schema model for the stream response. |
ResponseModel
Property | Type | Description |
---|
name | string | Name of the response model. |
schema | z.AnyZodObject | The Zod schema for validation. |
description | string | A description of the response model. |
OAIStream
OAIStream({ res }: OaiStreamArgs): ReadableStream<Uint8Array>
OaiStreamArgs
Property | Type | Description |
---|
res | Stream | The stream of data from OpenAI or AnyScale. |