Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Stream to use eventstream-parser library #214

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -811,3 +811,11 @@ You can call this method directly to make other requests to the API.
## TypeScript

The `Replicate` constructor and all `replicate.*` methods are fully typed.

## Vendored Dependencies

We have a few dependencies that have been bundled into the vendor directory rather than adding external npm dependencies.

These have been generated using bundlejs.com and copied into the appropriate directory along with the license and repository information.

* [eventsource-parser/stream](https://bundlejs.com/?bundle&q=eventsource-parser%40latest%2Fstream&config=%7B%22esbuild%22%3A%7B%22format%22%3A%22cjs%22%2C%22minify%22%3Afalse%2C%22platform%22%3A%22neutral%22%7D%7D)
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"$schema": "https://biomejs.dev/schemas/1.0.0/schema.json",
"files": {
"ignore": [".wrangler", "vendor/*"]
},
"formatter": {
"indentStyle": "space",
"indentWidth": 2
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ declare module "replicate" {
signature?: string;
},
secret: string
): boolean;
): Promise<boolean>;

export function parseProgressFromLogs(logs: Prediction | string): {
percentage: number;
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ApiError = require("./lib/error");
const ModelVersionIdentifier = require("./lib/identifier");
const { Stream } = require("./lib/stream");
const { createReadableStream } = require("./lib/stream");
const {
withAutomaticRetries,
validateWebhook,
Expand Down Expand Up @@ -289,7 +289,11 @@ class Replicate {

if (prediction.urls && prediction.urls.stream) {
const { signal } = options;
const stream = new Stream(prediction.urls.stream, { signal });
const stream = createReadableStream({
url: prediction.urls.stream,
fetch: this.fetch,
options: { signal },
});
yield* stream;
} else {
throw new Error("Prediction does not support streaming");
Expand Down
Loading
Loading