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

Deprecate stream parameter for predictions.create #291

Merged
merged 2 commits into from
Sep 23, 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
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ declare module "replicate" {
model?: string;
version?: string;
input: object;
/** @deprecated */
stream?: boolean;
webhook?: string;
webhook_events_filter?: WebhookEventType[];
Expand Down
2 changes: 0 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,11 @@ class Replicate {
prediction = await this.predictions.create({
...data,
version: identifier.version,
stream: true,
});
} else if (identifier.owner && identifier.name) {
prediction = await this.predictions.create({
...data,
model: `${identifier.owner}/${identifier.name}`,
stream: true,
});
} else {
throw new Error("Invalid model version identifier");
Expand Down
20 changes: 0 additions & 20 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ describe("Replicate client", () => {
prompt: "Tell me a story",
data,
},
stream: true,
});

expect(actual?.input.data).toEqual(expected);
Expand Down Expand Up @@ -385,7 +384,6 @@ describe("Replicate client", () => {
prompt: "Tell me a story",
data,
},
stream: true,
});
}).rejects.toThrowError(
expect.objectContaining({
Expand All @@ -396,24 +394,6 @@ describe("Replicate client", () => {
}
);

test("Passes stream parameter to API endpoint", async () => {
nock(BASE_URL)
.post("/predictions")
.reply(201, (_uri, body) => {
expect((body as any).stream).toBe(true);
return body;
});

await client.predictions.create({
version:
"5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
input: {
prompt: "Tell me a story",
},
stream: true,
});
});

test("Throws an error if webhook URL is invalid", async () => {
await expect(async () => {
await client.predictions.create({
Expand Down
6 changes: 2 additions & 4 deletions lib/predictions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const { transformFileInputs } = require("./util");
* @param {object} options.input - Required. An object with the model inputs
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
* @param {string[]} [options.webhook_events_filter] - You can change which events trigger webhook requests by specifying webhook events (`start`|`output`|`logs`|`completed`)
* @param {boolean} [options.stream] - Whether to stream the prediction output. Defaults to false
* @param {boolean} [options.stream] - Whether to stream the prediction output. Defaults to false. Streaming is now enabled by default for all predictions. For more information, see https://replicate.com/changelog/2024-07-15-streams-always-available-stream-parameter-deprecated
* @returns {Promise<object>} Resolves with the created prediction
*/
async function createPrediction(options) {
const { model, version, stream, input, ...data } = options;
const { model, version, input, ...data } = options;

if (data.webhook) {
try {
Expand All @@ -36,7 +36,6 @@ async function createPrediction(options) {
this.fileEncodingStrategy
),
version,
stream,
},
});
} else if (model) {
Expand All @@ -49,7 +48,6 @@ async function createPrediction(options) {
input,
this.fileEncodingStrategy
),
stream,
},
});
} else {
Expand Down
Loading