Skip to content

Commit

Permalink
docs: add ReplicateStream api-reference documentation (vercel#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLeiter authored Aug 7, 2023
1 parent 36571f9 commit 97ff0ef
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 104 deletions.
5 changes: 3 additions & 2 deletions docs/pages/docs/api-reference/_meta.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"use-chat": "useChat",
"use-completion": "useCompletion",
"huggingface-stream": "HuggingFaceStream",
"ai-stream": "AIStream",
"anthropic-stream": "AnthropicStream",
"huggingface-stream": "HuggingFaceStream",
"langchain-stream": "LangChainStream",
"openai-stream": "OpenAIStream",
"replicate-stream": "ReplicateStream",
"streaming-text-response": "StreamingTextResponse",
"ai-stream": "AIStream",
"stream-to-response": "streamToResponse",
"tokens": "<Tokens />"
}
21 changes: 21 additions & 0 deletions docs/pages/docs/api-reference/replicate-stream.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ReplicateStream

## `ReplicateStream(pre: Prediction, cb?: AIStreamCallbacks): Promise<ReadableStream>` [#replicatestream]

The `ReplicateStream` function is a utility that handles extracting the stream from the output of [Replicate's](https://www.replicate.com) API.
It expects a `Prediction` object as returned by the [Replicate JavaScript SDK](https://github.com/replicate/replicate-javascript), and returns a `ReadableStream`.
Unlike other wrappers, `ReplicateStream` returns a `Promise` because it makes a `fetch` call to the [Replicate streaming API](https://github.com/replicate/replicate-javascript#streaming) under the hood.

## Parameters

### `pre: Prediction`

The `Prediction` object returned by the Replicate JavaScript SDK

### `cb?: AIStreamCallbacks`

This optional parameter can be an object containing callback functions to handle the start, each token, and completion of the AI response. In the absence of this parameter, default behavior is implemented.

## Example

See our [Replicate Guide](/docs/guides/providers/replicate) for examples.
4 changes: 2 additions & 2 deletions examples/next-huggingface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
},
"dependencies": {
"@huggingface/inference": "^2.5.1",
"next": "13.4.12",
"ai": "2.1.32",
"next": "13.4.4-canary.11",
"react": "18.2.0",
"react-dom": "^18.2.0"
},
Expand All @@ -21,7 +21,7 @@
"@types/react-dom": "18.2.4",
"autoprefixer": "^10.4.14",
"eslint": "^7.32.0",
"eslint-config-next": "13.4.4-canary.11",
"eslint-config-next": "13.4.12",
"postcss": "^8.4.23",
"tailwindcss": "^3.3.2",
"typescript": "5.1.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/next-langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"ai": "2.1.32",
"langchain": "^0.0.103",
"next": "13.4.4-canary.11",
"next": "13.4.12",
"react": "18.2.0",
"react-dom": "^18.2.0"
},
Expand All @@ -21,7 +21,7 @@
"@types/react-dom": "18.2.4",
"autoprefixer": "^10.4.14",
"eslint": "^7.32.0",
"eslint-config-next": "13.4.4-canary.11",
"eslint-config-next": "13.4.12",
"postcss": "^8.4.23",
"tailwindcss": "^3.3.2",
"typescript": "5.1.3"
Expand Down
6 changes: 3 additions & 3 deletions examples/next-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"lint": "next lint"
},
"dependencies": {
"ai": "^2.1.32",
"next": "13.4.4-canary.11",
"ai": "^2.1.31",
"next": "13.4.12",
"openai-edge": "^1.1.0",
"react": "18.2.0",
"react-dom": "^18.2.0"
Expand All @@ -21,7 +21,7 @@
"@types/react-dom": "18.2.4",
"autoprefixer": "^10.4.14",
"eslint": "^7.32.0",
"eslint-config-next": "13.4.4-canary.11",
"eslint-config-next": "13.4.12",
"postcss": "^8.4.23",
"tailwindcss": "^3.3.2",
"typescript": "5.1.3"
Expand Down
4 changes: 2 additions & 2 deletions examples/next-replicate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"ai": "^2.1.29",
"next": "13.4.4-canary.11",
"next": "13.4.12",
"react": "18.2.0",
"react-dom": "^18.2.0",
"replicate": "^0.14.1"
Expand All @@ -21,7 +21,7 @@
"@types/react-dom": "18.2.4",
"autoprefixer": "^10.4.14",
"eslint": "^7.32.0",
"eslint-config-next": "13.4.4-canary.11",
"eslint-config-next": "13.4.12",
"postcss": "^8.4.23",
"tailwindcss": "^3.3.2",
"typescript": "5.1.3"
Expand Down
Loading

0 comments on commit 97ff0ef

Please sign in to comment.