Skip to content

add support for image-to-image models on Replicate #1427

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

Closed
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 packages/inference/src/lib/getProviderHelper.ts
Original file line number Diff line number Diff line change
@@ -133,6 +133,7 @@ export const PROVIDERS: Record<InferenceProvider, Partial<Record<InferenceTask,
"text-generation": new OvhCloud.OvhCloudTextGenerationTask(),
},
replicate: {
"image-to-image": new Replicate.ReplicateImageToImageTask(),
"text-to-image": new Replicate.ReplicateTextToImageTask(),
"text-to-speech": new Replicate.ReplicateTextToSpeechTask(),
"text-to-video": new Replicate.ReplicateTextToVideoTask(),
24 changes: 23 additions & 1 deletion packages/inference/src/providers/replicate.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,12 @@ import { InferenceOutputError } from "../lib/InferenceOutputError";
import { isUrl } from "../lib/isUrl";
import type { BodyParams, HeaderParams, UrlParams } from "../types";
import { omit } from "../utils/omit";
import { TaskProviderHelper, type TextToImageTaskHelper, type TextToVideoTaskHelper } from "./providerHelper";
import {
TaskProviderHelper,
type TextToImageTaskHelper,
type TextToVideoTaskHelper,
type ImageToImageTaskHelper,
} from "./providerHelper";
export interface ReplicateOutput {
output?: string | string[];
}
@@ -152,3 +157,20 @@ export class ReplicateTextToVideoTask extends ReplicateTask implements TextToVid
throw new InferenceOutputError("Expected { output: string }");
}
}

export class ReplicateImageToImageTask extends ReplicateTask implements ImageToImageTaskHelper {
override async getResponse(response: ReplicateOutput): Promise<Blob> {
if (
typeof response === "object" &&
!!response &&
"output" in response &&
typeof response.output === "string" &&
isUrl(response.output)
) {
const urlResponse = await fetch(response.output);
return await urlResponse.blob();
}

throw new InferenceOutputError("Expected { output: string }");
}
}
Loading
Oops, something went wrong.