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

feat (ai/core): add experimental generateImage function #4056

Merged
merged 29 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
image
  • Loading branch information
lgrammel committed Dec 10, 2024
commit d162d32344a3e45d218a8ef5e2ffa10fc92c82fa
5 changes: 5 additions & 0 deletions packages/ai/core/generate-image/generate-image-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ The result of a `generateImage` call.
It contains the images and additional information.
*/
export interface GenerateImageResult {
/**
The first image that was generated.
*/
readonly image: string;

/**
The images that were generated (base64 encoded).
*/
Expand Down
20 changes: 15 additions & 5 deletions packages/ai/core/generate-image/generate-image.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,25 @@ describe('generateImage', () => {
const result = await generateImage({
model: new MockImageModelV1({
doGenerate: async () => {
return { images: ['base64-image-data', 'base64-image-data'] };
return { images: ['base64-image-1', 'base64-image-2'] };
},
}),
prompt,
});

expect(result.images).toStrictEqual([
'base64-image-data',
'base64-image-data',
]);
expect(result.images).toStrictEqual(['base64-image-1', 'base64-image-2']);
});

it('should return the first image', async () => {
const result = await generateImage({
model: new MockImageModelV1({
doGenerate: async () => {
return { images: ['base64-image-1', 'base64-image-2'] };
},
}),
prompt,
});

expect(result.image).toStrictEqual('base64-image-1');
});
});
4 changes: 4 additions & 0 deletions packages/ai/core/generate-image/generate-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ class DefaultGenerateImageResult implements GenerateImageResult {
constructor(options: { images: GenerateImageResult['images'] }) {
this.images = options.images;
}

get image() {
return this.images[0];
}
}
Loading