diff --git a/common/api-review/generative-ai.api.md b/common/api-review/generative-ai.api.md index 17ff843..7ab9729 100644 --- a/common/api-review/generative-ai.api.md +++ b/common/api-review/generative-ai.api.md @@ -645,29 +645,17 @@ export interface ImageGenerationPredictResponseImageData { // @public export interface ImageGenerationRequest { - // (undocumented) aspectRatio?: "1:1" | "9:16" | "16:9" | "4:3" | "3:4"; - // (undocumented) compressionQuality?: number; - // (undocumented) guidanceScale?: number; - // (undocumented) height?: number; - // (undocumented) language?: string; - // (undocumented) negativePrompt?: string; - // (undocumented) numberOfImages?: number; - // (undocumented) outputMimeType?: "image/png" | "image/jpeg"; - // (undocumented) personGeneration?: "dont_allow" | "allow_adult"; - // (undocumented) prompt: string; - // (undocumented) safetyFilterLevel?: "block_low_and_above" | "block_medium_and_above" | "block_only_high"; - // (undocumented) width?: number; } diff --git a/src/gen-ai.test.ts b/src/gen-ai.test.ts index fe2565b..f06c1c6 100644 --- a/src/gen-ai.test.ts +++ b/src/gen-ai.test.ts @@ -15,7 +15,11 @@ * limitations under the License. */ import { ModelParams } from "../types"; -import { GenerativeModel, GoogleGenerativeAI, ImageGenerationModel } from "./gen-ai"; +import { + GenerativeModel, + GoogleGenerativeAI, + ImageGenerationModel, +} from "./gen-ai"; import { expect } from "chai"; const fakeContents = [{ role: "user", parts: [{ text: "hello" }] }]; diff --git a/src/gen-ai.ts b/src/gen-ai.ts index b7d705c..be07b78 100644 --- a/src/gen-ai.ts +++ b/src/gen-ai.ts @@ -128,4 +128,4 @@ export class GoogleGenerativeAI { requestOptions, ); } -} \ No newline at end of file +} diff --git a/src/methods/generate-images.ts b/src/methods/generate-images.ts index ea2b029..f4d2880 100644 --- a/src/methods/generate-images.ts +++ b/src/methods/generate-images.ts @@ -42,5 +42,7 @@ export async function generateImages( ); const responseJson: ImageGenerationPredictResponse = await response.json(); return convertToImageGenerationResponse( - predictRequest.parameters, responseJson); + predictRequest.parameters, + responseJson, + ); } diff --git a/src/models/vision-model.ts b/src/models/vision-model.ts index 034d2fb..0661e96 100644 --- a/src/models/vision-model.ts +++ b/src/models/vision-model.ts @@ -45,11 +45,19 @@ export class ImageGenerationModel { } } /** - * Generates image based on the request. + * Makes a single non-streaming call to the model + * and returns an object containing a single {@link ImageGenerationResponse}. + * + * Inside the response there will be generated pictures specified by + * numberOfImages in {@link ImageGenerationRequest} + * + * Fields set in the optional {@link SingleRequestOptions} parameter will + * take precedence over the {@link RequestOptions} values provided to + * {@link GoogleGenerativeAI.getImageGenerationModel }. */ async generateImages( request: ImageGenerationRequest | string, - requestOptions: SingleRequestOptions = {} + requestOptions: SingleRequestOptions = {}, ): Promise { const generativeModelRequestOptions: SingleRequestOptions = { ...this._requestOptions, diff --git a/src/requests/request.ts b/src/requests/request.ts index b18099f..592fea0 100644 --- a/src/requests/request.ts +++ b/src/requests/request.ts @@ -39,7 +39,7 @@ export enum Task { COUNT_TOKENS = "countTokens", EMBED_CONTENT = "embedContent", BATCH_EMBED_CONTENTS = "batchEmbedContents", - PREDICT = "predict" + PREDICT = "predict", } export class RequestUrl { diff --git a/test-integration/node/generate-image.test.ts b/test-integration/node/generate-image.test.ts index 7356dea..c87bbe9 100644 --- a/test-integration/node/generate-image.test.ts +++ b/test-integration/node/generate-image.test.ts @@ -17,9 +17,7 @@ import { expect, use } from "chai"; import * as chaiAsPromised from "chai-as-promised"; -import { - GoogleGenerativeAI -} from "../.."; +import { GoogleGenerativeAI } from "../.."; use(chaiAsPromised); @@ -32,8 +30,9 @@ describe("generateImage", function () { this.slow(20e3); it("non-streaming, simple interface", async () => { const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); - const model = genAI.getImageGenerationModel( - {model: "imagen-3.0-generate-001"}); + const model = genAI.getImageGenerationModel({ + model: "imagen-3.0-generate-001", + }); const result = await model.generateImages("A fluffy cat"); console.log(result); expect(result.images.length).equals(1); diff --git a/types/requests.ts b/types/requests.ts index d4fa6b9..9ae9098 100644 --- a/types/requests.ts +++ b/types/requests.ts @@ -248,7 +248,7 @@ export interface CodeExecutionTool { /** * Request message for [PredictionService.Predict][]. - * @public + * This is an internal class. Please do not depend on it. */ export interface PredictRequest { /** @@ -270,19 +270,72 @@ export interface PredictRequest { * @public */ export interface ImageGenerationRequest { + /** + * Text prompt for the image. + */ prompt: string; + /** + * A description of what you want to omit in the generated images. + */ negativePrompt?: string; + /** + * Number of images to generate. Range: 1..8. + */ numberOfImages?: number; + /** + * Width of the image. One of the Width/Height sizes must be 256 or 1024. + */ width?: number; + /** + * Height of the image. One of the Width/Height sizes must be 256 or 1024. + */ height?: number; + /** + * Changes the aspect ratio of the generated image Supported + * values are: + * * "1:1" : 1:1 aspect ratio + * * "9:16" : 9:16 aspect ratio + * * "16:9" : 16:9 aspect ratio + * * "4:3" : 4:3 aspect ratio + * * "3:4" : 3:4 aspect_ratio + */ aspectRatio?: "1:1" | "9:16" | "16:9" | "4:3" | "3:4"; + /** + * Controls the strength of the prompt. Suggested values are - * 0-9 (low + * strength) * 10-20 (medium strength) * 21+ (high strength) + */ guidanceScale?: number; + /** + * hich image format should the output be saved as. + * Supported values: * image/png: Save as a PNG image * image/jpeg: Save as + * a JPEG image + */ outputMimeType?: "image/png" | "image/jpeg"; + /** + * Level of compression if the output mime type is selected to be image/jpeg. + * Float between 0 to 100 + */ compressionQuality?: number; + /** + * Language of the text prompt for the image. Default: None. Supported values + * are `"en"` for English, `"hi"` for Hindi, `"ja"` for Japanese, `"ko"` + * for Korean, and `"auto"` for automatic language detection. + */ language?: string; + /** + * Adds a filter level to Safety filtering. Supported values are: + * * "block_most" : Strongest filtering level, most strict blocking + * * "block_some" : Block some problematic prompts and responses + * * "block_few" : Block fewer problematic prompts and responses + */ safetyFilterLevel?: | "block_low_and_above" | "block_medium_and_above" | "block_only_high"; + /** + * Allow generation of people by the model Supported values are: + * * "dont_allow" : Block generation of people + * * "allow_adult" : Generate adults, but not children + */ personGeneration?: "dont_allow" | "allow_adult"; } diff --git a/types/responses.ts b/types/responses.ts index 8a54d6a..35922d6 100644 --- a/types/responses.ts +++ b/types/responses.ts @@ -243,7 +243,7 @@ export interface ErrorDetails { /** * Each image data for response of [PredictionService.Predict]. - * @public + * This is an internal class. Please do not depend on it. */ export interface ImageGenerationPredictResponseImageData { bytesBase64Encoded: string @@ -252,7 +252,7 @@ export interface ImageGenerationPredictResponseImageData { /** * Response message for [PredictionService.Predict]. - * @public + * This is an internal class. Please do not depend on it. */ export interface ImageGenerationPredictResponse { /**