-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (ai/core): generate many images with parallel model calls (#4307)
- Loading branch information
Showing
6 changed files
with
206 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'ai': patch | ||
--- | ||
|
||
feat (ai/core): generate many images with parallel model calls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { openai } from '@ai-sdk/openai'; | ||
import { experimental_generateImage as generateImage } from 'ai'; | ||
import 'dotenv/config'; | ||
import fs from 'fs'; | ||
|
||
async function main() { | ||
const { images } = await generateImage({ | ||
model: openai.image('dall-e-3'), | ||
n: 3, // 3 calls; dall-e-3 can only generate 1 image at a time | ||
prompt: 'Santa Claus driving a Cadillac', | ||
}); | ||
|
||
for (const image of images) { | ||
const filename = `image-${Date.now()}.png`; | ||
fs.writeFileSync(filename, image.uint8Array); | ||
console.log(`Image saved to ${filename}`); | ||
} | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters