Skip to content

Commit 249403f

Browse files
authored
fix broken image step (#153)
1 parent 685f9c5 commit 249403f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

plugins/ai-gateway/steps/generate-image.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import "server-only";
22

3-
import type { ImageModelV2 } from "@ai-sdk/provider";
43
import {
54
createGateway,
65
experimental_generateImage as generateImage,
@@ -15,8 +14,8 @@ type GenerateImageResult =
1514
| { success: false; error: string };
1615

1716
export type GenerateImageCoreInput = {
18-
imageModel: ImageModelV2;
19-
imagePrompt: string;
17+
imageModel?: string;
18+
imagePrompt?: string;
2019
};
2120

2221
export type GenerateImageInput = StepInput &
@@ -41,16 +40,24 @@ async function stepHandler(
4140
};
4241
}
4342

43+
const modelId = input.imageModel || "google/imagen-4.0-generate";
44+
const promptText = input.imagePrompt || "";
45+
46+
if (!promptText || promptText.trim() === "") {
47+
return {
48+
success: false,
49+
error: "Prompt is required for image generation",
50+
};
51+
}
52+
4453
try {
4554
const gateway = createGateway({
4655
apiKey,
4756
});
48-
49-
// biome-ignore lint/suspicious/noExplicitAny: AI gateway model ID is dynamic
50-
const modelId = (input.imageModel ?? "google/imagen-4.0-generate") as any;
5157
const result = await generateImage({
52-
model: gateway.imageModel(modelId),
53-
prompt: input.imagePrompt,
58+
// biome-ignore lint/suspicious/noExplicitAny: AI gateway model ID is dynamic
59+
model: gateway.imageModel(modelId as any),
60+
prompt: promptText,
5461
size: "1024x1024",
5562
});
5663

0 commit comments

Comments
 (0)