Skip to content

Commit

Permalink
Update doc string
Browse files Browse the repository at this point in the history
  • Loading branch information
junyanxu committed Oct 9, 2024
1 parent 258584c commit a38ac67
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 26 deletions.
12 changes: 0 additions & 12 deletions common/api-review/generative-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 5 additions & 1 deletion src/gen-ai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" }] }];
Expand Down
2 changes: 1 addition & 1 deletion src/gen-ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ export class GoogleGenerativeAI {
requestOptions,
);
}
}
}
4 changes: 3 additions & 1 deletion src/methods/generate-images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ export async function generateImages(
);
const responseJson: ImageGenerationPredictResponse = await response.json();
return convertToImageGenerationResponse(
predictRequest.parameters, responseJson);
predictRequest.parameters,
responseJson,
);
}
12 changes: 10 additions & 2 deletions src/models/vision-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageGenerationResponse> {
const generativeModelRequestOptions: SingleRequestOptions = {
...this._requestOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/requests/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export enum Task {
COUNT_TOKENS = "countTokens",
EMBED_CONTENT = "embedContent",
BATCH_EMBED_CONTENTS = "batchEmbedContents",
PREDICT = "predict"
PREDICT = "predict",
}

export class RequestUrl {
Expand Down
9 changes: 4 additions & 5 deletions test-integration/node/generate-image.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

import { expect, use } from "chai";
import * as chaiAsPromised from "chai-as-promised";
import {
GoogleGenerativeAI
} from "../..";
import { GoogleGenerativeAI } from "../..";

use(chaiAsPromised);

Expand All @@ -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);
Expand Down
55 changes: 54 additions & 1 deletion types/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -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";
}
4 changes: 2 additions & 2 deletions types/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
/**
Expand Down

0 comments on commit a38ac67

Please sign in to comment.