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
size
  • Loading branch information
lgrammel committed Dec 10, 2024
commit aa6c794e448c8f9f24e90cdb88a8493c5be5bf8c
4 changes: 3 additions & 1 deletion packages/ai/core/generate-image/generate-image.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ describe('generateImage', () => {
},
}),
prompt,
size: '1024x1024',
headers: { 'custom-request-header': 'request-header-value' },
abortSignal,
});

expect(capturedArgs).toStrictEqual({
prompt,
n: 1,
prompt,
size: '1024x1024',
headers: { 'custom-request-header': 'request-header-value' },
abortSignal,
});
Expand Down
7 changes: 7 additions & 0 deletions packages/ai/core/generate-image/generate-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export async function generateImage({
model,
prompt,
n,
size,
maxRetries: maxRetriesArg,
abortSignal,
headers,
Expand All @@ -37,6 +38,11 @@ Number of images to generate.
*/
n?: number;

/**
Size of the images to generate. Must have the format `{width}x{height}`.
*/
size?: `${number}x${number}`;

/**
Maximum number of retries per embedding model call. Set to 0 to disable retries.

Expand All @@ -63,6 +69,7 @@ Only applicable for HTTP-based providers.
n: n ?? 1,
abortSignal,
headers,
size,
}),
);

Expand Down
3 changes: 2 additions & 1 deletion packages/openai/src/openai-image-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class OpenAIImageModel implements ImageModelV1 {
async doGenerate({
prompt,
n,
size,
headers,
abortSignal,
}: Parameters<ImageModelV1['doGenerate']>[0]): Promise<
Expand All @@ -43,7 +44,7 @@ export class OpenAIImageModel implements ImageModelV1 {
model: this.modelId,
prompt,
n,
// TODO size
size,
// TODO passthrough provider options
response_format: 'b64_json',
},
Expand Down
5 changes: 5 additions & 0 deletions packages/provider/src/image-model/v1/image-model-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ Number of images to generate.
*/
n: number;

/**
Size of the images to generate. Must have the format `{width}x{height}`.
*/
size: `${number}x${number}` | undefined;

/**
Abort signal for cancelling the operation.
*/
Expand Down
Loading