Tuning

तरीका: tuneModels.generateContent

दिए गए इनपुट GenerateContentRequest मॉडल से रिस्पॉन्स जनरेट करता है.

इनपुट सुविधाएं, अलग-अलग मॉडल के लिए अलग-अलग होती हैं. इनमें ट्यून किए जाने वाले मॉडल भी शामिल हैं. ज़्यादा जानकारी के लिए, मॉडल गाइड और ट्यूनिंग गाइड देखें.

एंडपॉइंट

पोस्ट https://generativelanguage.googleapis.com/v1beta/{model=tunedModels/*}:generateContent

पाथ पैरामीटर

model string

ज़रूरी है. नतीजे जनरेट करने के लिए इस्तेमाल किए जाने वाले Model का नाम.

फ़ॉर्मैट: name=models/{model}. यह tunedModels/{tunedmodel} का रूप लेता है.

अनुरोध का मुख्य भाग

अनुरोध के मुख्य हिस्से में, यहां दिए गए स्ट्रक्चर का डेटा शामिल होता है:

फ़ील्ड
contents[] object (Content)

ज़रूरी है. मॉडल के साथ हुई मौजूदा बातचीत का कॉन्टेंट.

सिंगल-टर्न वाली क्वेरी के लिए, यह एक इंस्टेंस होता है. बारी-बारी से आने वाली क्वेरी के लिए, यह दोहराया गया फ़ील्ड होता है. इसमें बातचीत का इतिहास और नया अनुरोध शामिल होता है.

tools[] object (Tool)

ज़रूरी नहीं. Tools की सूची, जिसका इस्तेमाल करके मॉडल अगला जवाब जनरेट कर सकता है.

Tool, कोड का एक हिस्सा होता है. इसकी मदद से सिस्टम, बाहरी सिस्टम से इंटरैक्ट कर पाता है, ताकि मॉडल की जानकारी और दायरे से बाहर कोई कार्रवाई या कार्रवाइयों का सेट पूरा कर सके. फ़िलहाल, सिर्फ़ Function टूल का इस्तेमाल किया जा सकता है.

toolConfig object (ToolConfig)

ज़रूरी नहीं. अनुरोध में बताए गए किसी भी Tool के लिए टूल कॉन्फ़िगरेशन.

safetySettings[] object (SafetySetting)

ज़रूरी नहीं. असुरक्षित कॉन्टेंट को ब्लॉक करने वाले यूनीक SafetySetting इंस्टेंस की सूची.

यह GenerateContentRequest.contents और GenerateContentResponse.candidates पर लागू किया जाएगा. हर SafetyCategory टाइप के लिए एक से ज़्यादा सेटिंग नहीं होनी चाहिए. यह एपीआई ऐसे सभी कॉन्टेंट और रिस्पॉन्स को ब्लॉक कर देगा जो इन सेटिंग के लिए तय थ्रेशोल्ड को पूरा नहीं कर पाते हैं. यह सूची, SafetySettings में दिए गए हर SafetyCategory के लिए डिफ़ॉल्ट सेटिंग को बदल देती है. अगर सूची में दिए गए किसी SafetyCategory के लिए कोई SafetySetting नहीं है, तो एपीआई उस कैटगरी के लिए डिफ़ॉल्ट सुरक्षा सेटिंग का इस्तेमाल करेगा. नुकसान की कैटगरी HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT, HARM_CATEGORY_HARASSMENT वाली कैटगरी.

systemInstruction object (Content)

ज़रूरी नहीं. डेवलपर ने सिस्टम के लिए निर्देश सेट किए हैं. फ़िलहाल, सिर्फ़ टेक्स्ट.

generationConfig object (GenerationConfig)

ज़रूरी नहीं. मॉडल जनरेशन और आउटपुट के लिए कॉन्फ़िगरेशन के विकल्प.

cachedContent string

ज़रूरी नहीं. सुझाव दिखाने के लिए, कॉन्टेक्स्ट के तौर पर इस्तेमाल की गई कैश मेमोरी में सेव किए गए कॉन्टेंट का नाम. ध्यान दें: इसे सिर्फ़ साफ़ तौर पर कैश मेमोरी में इस्तेमाल करने के लिए इस्तेमाल किया जाता है, जहां उपयोगकर्ता कैश मेमोरी को कंट्रोल कर सकते हैं (जैसे, किस कॉन्टेंट को कैश मेमोरी में सेव करना चाहिए) और लागत में बचत की गारंटी पाएं. फ़ॉर्मैट: cachedContents/{cachedContent}

अनुरोध का उदाहरण

टेक्स्ट

Python

model = genai.GenerativeModel("gemini-1.5-flash")
response = model.generate_content("Write a story about a magic backpack.")
print(response.text)

Node.js

// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

const prompt = "Write a story about a magic backpack.";

const result = await model.generateContent(prompt);
console.log(result.response.text());

Kotlin

val generativeModel =
    GenerativeModel(
        // Specify a Gemini model appropriate for your use case
        modelName = "gemini-1.5-flash",
        // Access your API key as a Build Configuration variable (see "Set up your API key" above)
        apiKey = BuildConfig.apiKey)

val prompt = "Write a story about a magic backpack."
val response = generativeModel.generateContent(prompt)
print(response.text)

Swift

let generativeModel =
  GenerativeModel(
    // Specify a Gemini model appropriate for your use case
    name: "gemini-1.5-flash",
    // Access your API key from your on-demand resource .plist file (see "Set up your API key"
    // above)
    apiKey: APIKey.default
  )

let prompt = "Write a story about a magic backpack."
let response = try await generativeModel.generateContent(prompt)
if let text = response.text {
  print(text)
}

Dart

final model = GenerativeModel(
  model: 'gemini-1.5-flash',
  apiKey: apiKey,
);
final prompt = 'Write a story about a magic backpack.';

final response = await model.generateContent([Content.text(prompt)]);
print(response.text);

Java

// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
    new GenerativeModel(
        /* modelName */ "gemini-1.5-flash",
        // Access your API key as a Build Configuration variable (see "Set up your API key"
        // above)
        /* apiKey */ BuildConfig.apiKey);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

Content content =
    new Content.Builder().addText("Write a story about a magic backpack.").build();

// For illustrative purposes only. You should use an executor that fits your needs.
Executor executor = Executors.newSingleThreadExecutor();

ListenableFuture<GenerateContentResponse> response = model.generateContent(content);
Futures.addCallback(
    response,
    new FutureCallback<GenerateContentResponse>() {
      @Override
      public void onSuccess(GenerateContentResponse result) {
        String resultText = result.getText();
        System.out.println(resultText);
      }

      @Override
      public void onFailure(Throwable t) {
        t.printStackTrace();
      }
    },
    executor);

इमेज

Python

import PIL.Image

model = genai.GenerativeModel("gemini-1.5-flash")
organ = PIL.Image.open(media / "organ.jpg")
response = model.generate_content(["Tell me about this instrument", organ])
print(response.text)

Node.js

// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

function fileToGenerativePart(path, mimeType) {
  return {
    inlineData: {
      data: Buffer.from(fs.readFileSync(path)).toString("base64"),
      mimeType,
    },
  };
}

const prompt = "Describe how this product might be manufactured.";
// Note: The only accepted mime types are some image types, image/*.
const imagePart = fileToGenerativePart(
  `${mediaPath}/jetpack.jpg`,
  "image/jpeg",
);

const result = await model.generateContent([prompt, imagePart]);
console.log(result.response.text());

Kotlin

val generativeModel =
    GenerativeModel(
        // Specify a Gemini model appropriate for your use case
        modelName = "gemini-1.5-flash",
        // Access your API key as a Build Configuration variable (see "Set up your API key" above)
        apiKey = BuildConfig.apiKey)

val image: Bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.image)
val inputContent = content {
  image(image)
  text("What's in this picture?")
}

val response = generativeModel.generateContent(inputContent)
print(response.text)

Swift

let generativeModel =
  GenerativeModel(
    // Specify a Gemini model appropriate for your use case
    name: "gemini-1.5-flash",
    // Access your API key from your on-demand resource .plist file (see "Set up your API key"
    // above)
    apiKey: APIKey.default
  )

guard let image = UIImage(systemName: "cloud.sun") else { fatalError() }

let prompt = "What's in this picture?"

let response = try await generativeModel.generateContent(image, prompt)
if let text = response.text {
  print(text)
}

Dart

final model = GenerativeModel(
  model: 'gemini-1.5-flash',
  apiKey: apiKey,
);

Future<DataPart> fileToPart(String mimeType, String path) async {
  return DataPart(mimeType, await File(path).readAsBytes());
}

final prompt = 'Describe how this product might be manufactured.';
final image = await fileToPart('image/jpeg', 'resources/jetpack.jpg');

final response = await model.generateContent([
  Content.multi([TextPart(prompt), image])
]);
print(response.text);

Java

// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
    new GenerativeModel(
        /* modelName */ "gemini-1.5-flash",
        // Access your API key as a Build Configuration variable (see "Set up your API key"
        // above)
        /* apiKey */ BuildConfig.apiKey);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

Bitmap image = BitmapFactory.decodeResource(context.getResources(), R.drawable.image);

Content content =
    new Content.Builder()
        .addText("What's different between these pictures?")
        .addImage(image)
        .build();

// For illustrative purposes only. You should use an executor that fits your needs.
Executor executor = Executors.newSingleThreadExecutor();

ListenableFuture<GenerateContentResponse> response = model.generateContent(content);
Futures.addCallback(
    response,
    new FutureCallback<GenerateContentResponse>() {
      @Override
      public void onSuccess(GenerateContentResponse result) {
        String resultText = result.getText();
        System.out.println(resultText);
      }

      @Override
      public void onFailure(Throwable t) {
        t.printStackTrace();
      }
    },
    executor);

ऑडियो

Python

model = genai.GenerativeModel("gemini-1.5-flash")
sample_audio = genai.upload_file(media / "sample.mp3")
response = model.generate_content(["Give me a summary of this audio file.", sample_audio])
print(response.text)

Node.js

// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

function fileToGenerativePart(path, mimeType) {
  return {
    inlineData: {
      data: Buffer.from(fs.readFileSync(path)).toString("base64"),
      mimeType,
    },
  };
}

const prompt = "Give me a summary of this audio file.";
// Note: The only accepted mime types are some image types, image/*.
const audioPart = fileToGenerativePart(
  `${mediaPath}/samplesmall.mp3`,
  "audio/mp3",
);

const result = await model.generateContent([prompt, audioPart]);
console.log(result.response.text());

वीडियो

Python

import time

# Video clip (CC BY 3.0) from https://peach.blender.org/download/
myfile = genai.upload_file(media / "Big_Buck_Bunny.mp4")
print(f"{myfile=}")

# Videos need to be processed before you can use them.
while myfile.state.name == "PROCESSING":
    print("processing video...")
    time.sleep(5)
    myfile = genai.get_file(myfile.name)

model = genai.GenerativeModel("gemini-1.5-flash")
result = model.generate_content([myfile, "Describe this video clip"])
print(f"{result.text=}")

Node.js

// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
// import { GoogleAIFileManager, FileState } from "@google/generative-ai/server";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

const fileManager = new GoogleAIFileManager(process.env.API_KEY);

const uploadResult = await fileManager.uploadFile(
  `${mediaPath}/Big_Buck_Bunny.mp4`,
  { mimeType: "video/mp4" },
);

let file = await fileManager.getFile(uploadResult.file.name);
while (file.state === FileState.PROCESSING) {
  process.stdout.write(".");
  // Sleep for 10 seconds
  await new Promise((resolve) => setTimeout(resolve, 10_000));
  // Fetch the file from the API again
  file = await fileManager.getFile(uploadResult.file.name);
}

if (file.state === FileState.FAILED) {
  throw new Error("Video processing failed.");
}

const prompt = "Describe this video clip";
const videoPart = {
  fileData: {
    fileUri: uploadResult.file.uri,
    mimeType: uploadResult.file.mimeType,
  },
};

const result = await model.generateContent([prompt, videoPart]);
console.log(result.response.text());

चैट करें

Python

model = genai.GenerativeModel("gemini-1.5-flash")
chat = model.start_chat(
    history=[
        {"role": "user", "parts": "Hello"},
        {"role": "model", "parts": "Great to meet you. What would you like to know?"},
    ]
)
response = chat.send_message("I have 2 dogs in my house.")
print(response.text)
response = chat.send_message("How many paws are in my house?")
print(response.text)

Node.js

// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
const chat = model.startChat({
  history: [
    {
      role: "user",
      parts: [{ text: "Hello" }],
    },
    {
      role: "model",
      parts: [{ text: "Great to meet you. What would you like to know?" }],
    },
  ],
});
let result = await chat.sendMessage("I have 2 dogs in my house.");
console.log(result.response.text());
result = await chat.sendMessage("How many paws are in my house?");
console.log(result.response.text());

शेल

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
      "contents": [
        {"role":"user",
         "parts":[{
           "text": "Hello"}]},
        {"role": "model",
         "parts":[{
           "text": "Great to meet you. What would you like to know?"}]},
        {"role":"user",
         "parts":[{
           "text": "I have two dogs in my house. How many paws are in my house?"}]},
      ]
    }' 2> /dev/null | grep "text"

Kotlin

val generativeModel =
    GenerativeModel(
        // Specify a Gemini model appropriate for your use case
        modelName = "gemini-1.5-flash",
        // Access your API key as a Build Configuration variable (see "Set up your API key" above)
        apiKey = BuildConfig.apiKey)

val chat =
    generativeModel.startChat(
        history =
            listOf(
                content(role = "user") { text("Hello, I have 2 dogs in my house.") },
                content(role = "model") {
                  text("Great to meet you. What would you like to know?")
                }))

val response = chat.sendMessage("How many paws are in my house?")
print(response.text)

Swift

let generativeModel =
  GenerativeModel(
    // Specify a Gemini model appropriate for your use case
    name: "gemini-1.5-flash",
    // Access your API key from your on-demand resource .plist file (see "Set up your API key"
    // above)
    apiKey: APIKey.default
  )

// Optionally specify existing chat history
let history = [
  ModelContent(role: "user", parts: "Hello, I have 2 dogs in my house."),
  ModelContent(role: "model", parts: "Great to meet you. What would you like to know?"),
]

// Initialize the chat with optional chat history
let chat = generativeModel.startChat(history: history)

// To generate text output, call sendMessage and pass in the message
let response = try await chat.sendMessage("How many paws are in my house?")
if let text = response.text {
  print(text)
}

Dart

final model = GenerativeModel(
  model: 'gemini-1.5-flash',
  apiKey: apiKey,
);
final chat = model.startChat(history: [
  Content.text('hello'),
  Content.model([TextPart('Great to meet you. What would you like to know?')])
]);
var response =
    await chat.sendMessage(Content.text('I have 2 dogs in my house.'));
print(response.text);
response =
    await chat.sendMessage(Content.text('How many paws are in my house?'));
print(response.text);

Java

// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
    new GenerativeModel(
        /* modelName */ "gemini-1.5-flash",
        // Access your API key as a Build Configuration variable (see "Set up your API key"
        // above)
        /* apiKey */ BuildConfig.apiKey);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

// (optional) Create previous chat history for context
Content.Builder userContentBuilder = new Content.Builder();
userContentBuilder.setRole("user");
userContentBuilder.addText("Hello, I have 2 dogs in my house.");
Content userContent = userContentBuilder.build();

Content.Builder modelContentBuilder = new Content.Builder();
modelContentBuilder.setRole("model");
modelContentBuilder.addText("Great to meet you. What would you like to know?");
Content modelContent = userContentBuilder.build();

List<Content> history = Arrays.asList(userContent, modelContent);

// Initialize the chat
ChatFutures chat = model.startChat(history);

// Create a new user message
Content.Builder userMessageBuilder = new Content.Builder();
userMessageBuilder.setRole("user");
userMessageBuilder.addText("How many paws are in my house?");
Content userMessage = userMessageBuilder.build();

// For illustrative purposes only. You should use an executor that fits your needs.
Executor executor = Executors.newSingleThreadExecutor();

// Send the message
ListenableFuture<GenerateContentResponse> response = chat.sendMessage(userMessage);

Futures.addCallback(
    response,
    new FutureCallback<GenerateContentResponse>() {
      @Override
      public void onSuccess(GenerateContentResponse result) {
        String resultText = result.getText();
        System.out.println(resultText);
      }

      @Override
      public void onFailure(Throwable t) {
        t.printStackTrace();
      }
    },
    executor);

कैश

Python

document = genai.upload_file(path=media / "a11.txt")
model_name = "gemini-1.5-flash-001"
cache = genai.caching.CachedContent.create(
    model=model_name,
    system_instruction="You are an expert analyzing transcripts.",
    contents=[document],
)
print(cache)

model = genai.GenerativeModel.from_cached_content(cache)
response = model.generate_content("Please summarize this transcript")
print(response.text)

Node.js

// Make sure to include these imports:
// import { GoogleAICacheManager, GoogleAIFileManager } from "@google/generative-ai/server";
// import { GoogleGenerativeAI } from "@google/generative-ai";
const cacheManager = new GoogleAICacheManager(process.env.API_KEY);
const fileManager = new GoogleAIFileManager(process.env.API_KEY);

const uploadResult = await fileManager.uploadFile(`${mediaPath}/a11.txt`, {
  mimeType: "text/plain",
});

const cacheResult = await cacheManager.create({
  model: "models/gemini-1.5-flash-001",
  contents: [
    {
      role: "user",
      parts: [
        {
          fileData: {
            fileUri: uploadResult.file.uri,
            mimeType: uploadResult.file.mimeType,
          },
        },
      ],
    },
  ],
});

console.log(cacheResult);

const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModelFromCachedContent(cacheResult);
const result = await model.generateContent(
  "Please summarize this transcript.",
);
console.log(result.response.text());

ट्यून किया गया मॉडल

Python

model = genai.GenerativeModel(model_name="tunedModels/my-increment-model")
result = model.generate_content("III")
print(result.text)  # "IV"

JSON मोड

Python

import typing_extensions as typing

class Recipe(typing.TypedDict):
    recipe_name: str

model = genai.GenerativeModel("gemini-1.5-pro-latest")
result = model.generate_content(
    "List a few popular cookie recipes.",
    generation_config=genai.GenerationConfig(
        response_mime_type="application/json", response_schema=list([Recipe])
    ),
)
print(result)

Node.js

// Make sure to include these imports:
// import { GoogleGenerativeAI, FunctionDeclarationSchemaType } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);

const schema = {
  description: "List of recipes",
  type: FunctionDeclarationSchemaType.ARRAY,
  items: {
    type: FunctionDeclarationSchemaType.OBJECT,
    properties: {
      recipeName: {
        type: FunctionDeclarationSchemaType.STRING,
        description: "Name of the recipe",
        nullable: false,
      },
    },
    required: ["recipeName"],
  },
};

const model = genAI.getGenerativeModel({
  model: "gemini-1.5-pro",
  generationConfig: {
    responseMimeType: "application/json",
    responseSchema: schema,
  },
});

const result = await model.generateContent(
  "List a few popular cookie recipes.",
);
console.log(result.response.text());

Kotlin

val generativeModel =
    GenerativeModel(
        // Specify a Gemini model appropriate for your use case
        modelName = "gemini-1.5-pro",
        // Access your API key as a Build Configuration variable (see "Set up your API key" above)
        apiKey = BuildConfig.apiKey,
        generationConfig = generationConfig {
            responseMimeType = "application/json"
            responseSchema = Schema(
                name = "recipes",
                description = "List of recipes",
                type = FunctionType.ARRAY,
                items = Schema(
                    name = "recipe",
                    description = "A recipe",
                    type = FunctionType.OBJECT,
                    properties = mapOf(
                        "recipeName" to Schema(
                            name = "recipeName",
                            description = "Name of the recipe",
                            type = FunctionType.STRING,
                            nullable = false
                        ),
                    ),
                    required = listOf("recipeName")
                ),
            )
        })

val prompt = "List a few popular cookie recipes."
val response = generativeModel.generateContent(prompt)
print(response.text)

Swift

let jsonSchema = Schema(
  type: .array,
  description: "List of recipes",
  items: Schema(
    type: .object,
    properties: [
      "recipeName": Schema(type: .string, description: "Name of the recipe", nullable: false),
    ],
    requiredProperties: ["recipeName"]
  )
)

let generativeModel = GenerativeModel(
  // Specify a model that supports controlled generation like Gemini 1.5 Pro
  name: "gemini-1.5-pro",
  // Access your API key from your on-demand resource .plist file (see "Set up your API key"
  // above)
  apiKey: APIKey.default,
  generationConfig: GenerationConfig(
    responseMIMEType: "application/json",
    responseSchema: jsonSchema
  )
)

let prompt = "List a few popular cookie recipes."
let response = try await generativeModel.generateContent(prompt)
if let text = response.text {
  print(text)
}

Dart

final schema = Schema.array(
    description: 'List of recipes',
    items: Schema.object(properties: {
      'recipeName':
          Schema.string(description: 'Name of the recipe.', nullable: false)
    }, requiredProperties: [
      'recipeName'
    ]));

final model = GenerativeModel(
    model: 'gemini-1.5-pro',
    apiKey: apiKey,
    generationConfig: GenerationConfig(
        responseMimeType: 'application/json', responseSchema: schema));

final prompt = 'List a few popular cookie recipes.';
final response = await model.generateContent([Content.text(prompt)]);
print(response.text);

Java

Schema<List<String>> schema =
    new Schema(
        /* name */ "recipes",
        /* description */ "List of recipes",
        /* format */ null,
        /* nullable */ false,
        /* list */ null,
        /* properties */ null,
        /* required */ null,
        /* items */ new Schema(
            /* name */ "recipe",
            /* description */ "A recipe",
            /* format */ null,
            /* nullable */ false,
            /* list */ null,
            /* properties */ Map.of(
                "recipeName",
                new Schema(
                    /* name */ "recipeName",
                    /* description */ "Name of the recipe",
                    /* format */ null,
                    /* nullable */ false,
                    /* list */ null,
                    /* properties */ null,
                    /* required */ null,
                    /* items */ null,
                    /* type */ FunctionType.STRING)),
            /* required */ null,
            /* items */ null,
            /* type */ FunctionType.OBJECT),
        /* type */ FunctionType.ARRAY);

GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.responseMimeType = "application/json";
configBuilder.responseSchema = schema;

GenerationConfig generationConfig = configBuilder.build();

// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
    new GenerativeModel(
        /* modelName */ "gemini-1.5-pro",
        // Access your API key as a Build Configuration variable (see "Set up your API key"
        // above)
        /* apiKey */ BuildConfig.apiKey,
        /* generationConfig */ generationConfig);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

Content content = new Content.Builder().addText("List a few popular cookie recipes.").build();

// For illustrative purposes only. You should use an executor that fits your needs.
Executor executor = Executors.newSingleThreadExecutor();

ListenableFuture<GenerateContentResponse> response = model.generateContent(content);
Futures.addCallback(
    response,
    new FutureCallback<GenerateContentResponse>() {
      @Override
      public void onSuccess(GenerateContentResponse result) {
        String resultText = result.getText();
        System.out.println(resultText);
      }

      @Override
      public void onFailure(Throwable t) {
        t.printStackTrace();
      }
    },
    executor);

कोड लागू करना

Python

model = genai.GenerativeModel(model_name="gemini-1.5-flash", tools="code_execution")
response = model.generate_content(
    (
        "What is the sum of the first 50 prime numbers? "
        "Generate and run code for the calculation, and make sure you get all 50."
    )
)

# Each `part` either contains `text`, `executable_code` or an `execution_result`
for part in result.candidates[0].content.parts:
    print(part, "\n")

print("-" * 80)
# The `.text` accessor joins the parts into a markdown compatible text representation.
print("\n\n", response.text)

Kotlin


val model = GenerativeModel(
    // Specify a Gemini model appropriate for your use case
    modelName = "gemini-1.5-pro",
    // Access your API key as a Build Configuration variable (see "Set up your API key" above)
    apiKey = BuildConfig.apiKey,
    tools = listOf(Tool.CODE_EXECUTION)
)

val response = model.generateContent("What is the sum of the first 50 prime numbers?")

// Each `part` either contains `text`, `executable_code` or an `execution_result`
println(response.candidates[0].content.parts.joinToString("\n"))

// Alternatively, you can use the `text` accessor which joins the parts into a markdown compatible
// text representation
println(response.text)

Java

// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
        new GenerativeModel(
                /* modelName */ "gemini-1.5-pro",
                // Access your API key as a Build Configuration variable (see "Set up your API key"
                // above)
                /* apiKey */ BuildConfig.apiKey,
                /* generationConfig */ null,
                /* safetySettings */ null,
                /* requestOptions */ new RequestOptions(),
                /* tools */ Collections.singletonList(Tool.CODE_EXECUTION));
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

Content inputContent =
        new Content.Builder().addText("What is the sum of the first 50 prime numbers?").build();

// For illustrative purposes only. You should use an executor that fits your needs.
Executor executor = Executors.newSingleThreadExecutor();

ListenableFuture<GenerateContentResponse> response = model.generateContent(inputContent);
Futures.addCallback(
        response,
        new FutureCallback<GenerateContentResponse>() {
            @Override
            public void onSuccess(GenerateContentResponse result) {
                // Each `part` either contains `text`, `executable_code` or an
                // `execution_result`
                Candidate candidate = result.getCandidates().get(0);
                for (Part part : candidate.getContent().getParts()) {
                    System.out.println(part);
                }

                // Alternatively, you can use the `text` accessor which joins the parts into a
                // markdown compatible text representation
                String resultText = result.getText();
                System.out.println(resultText);
            }

            @Override
            public void onFailure(Throwable t) {
                t.printStackTrace();
            }
        },
        executor);

फ़ंक्शन कॉलिंग

Python

def add(a: float, b: float):
    """returns a + b."""
    return a + b

def subtract(a: float, b: float):
    """returns a - b."""
    return a - b

def multiply(a: float, b: float):
    """returns a * b."""
    return a * b

def divide(a: float, b: float):
    """returns a / b."""
    return a / b

model = genai.GenerativeModel(
    model_name="gemini-1.5-flash", tools=[add, subtract, multiply, divide]
)
chat = model.start_chat(enable_automatic_function_calling=True)
response = chat.send_message(
    "I have 57 cats, each owns 44 mittens, how many mittens is that in total?"
)
print(response.text)

Node.js

// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
async function setLightValues(brightness, colorTemperature) {
  // This mock API returns the requested lighting values
  return {
    brightness,
    colorTemperature,
  };
}

const controlLightFunctionDeclaration = {
  name: "controlLight",
  parameters: {
    type: "OBJECT",
    description: "Set the brightness and color temperature of a room light.",
    properties: {
      brightness: {
        type: "NUMBER",
        description:
          "Light level from 0 to 100. Zero is off and 100 is full brightness.",
      },
      colorTemperature: {
        type: "STRING",
        description:
          "Color temperature of the light fixture which can be `daylight`, `cool` or `warm`.",
      },
    },
    required: ["brightness", "colorTemperature"],
  },
};

// Executable function code. Put it in a map keyed by the function name
// so that you can call it once you get the name string from the model.
const functions = {
  controlLight: ({ brightness, colorTemperature }) => {
    return setLightValues(brightness, colorTemperature);
  },
};

const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
  model: "gemini-1.5-flash",
  tools: { functionDeclarations: [controlLightFunctionDeclaration] },
});
const chat = model.startChat();
const prompt = "Dim the lights so the room feels cozy and warm.";

// Send the message to the model.
const result = await chat.sendMessage(prompt);

// For simplicity, this uses the first function call found.
const call = result.response.functionCalls()[0];

if (call) {
  // Call the executable function named in the function call
  // with the arguments specified in the function call and
  // let it call the hypothetical API.
  const apiResponse = await functions[call.name](call.args);

  // Send the API response back to the model so it can generate
  // a text response that can be displayed to the user.
  const result2 = await chat.sendMessage([
    {
      functionResponse: {
        name: "controlLight",
        response: apiResponse,
      },
    },
  ]);

  // Log the text response.
  console.log(result2.response.text());
}

Kotlin

fun multiply(a: Double, b: Double) = a * b

val multiplyDefinition = defineFunction(
    name = "multiply",
    description = "returns the product of the provided numbers.",
    parameters = listOf(
    Schema.double("a", "First number"),
    Schema.double("b", "Second number")
    )
)

val usableFunctions = listOf(multiplyDefinition)

val generativeModel =
    GenerativeModel(
        // Specify a Gemini model appropriate for your use case
        modelName = "gemini-1.5-flash",
        // Access your API key as a Build Configuration variable (see "Set up your API key" above)
        apiKey = BuildConfig.apiKey,
        // List the functions definitions you want to make available to the model
        tools = listOf(Tool(usableFunctions))
    )

val chat = generativeModel.startChat()
val prompt = "I have 57 cats, each owns 44 mittens, how many mittens is that in total?"

// Send the message to the generative model
var response = chat.sendMessage(prompt)

// Check if the model responded with a function call
response.functionCalls.first { it.name == "multiply" }.apply {
    val a: String by args
    val b: String by args

    val result = JSONObject(mapOf("result" to multiply(a.toDouble(), b.toDouble())))
    response = chat.sendMessage(
        content(role = "function") {
            part(FunctionResponsePart("multiply", result))
        }
    )
}

// Whenever the model responds with text, show it in the UI
response.text?.let { modelResponse ->
    println(modelResponse)
}

Swift

// Calls a hypothetical API to control a light bulb and returns the values that were set.
func controlLight(brightness: Double, colorTemperature: String) -> JSONObject {
  return ["brightness": .number(brightness), "colorTemperature": .string(colorTemperature)]
}

let generativeModel =
  GenerativeModel(
    // Use a model that supports function calling, like a Gemini 1.5 model
    name: "gemini-1.5-flash",
    // Access your API key from your on-demand resource .plist file (see "Set up your API key"
    // above)
    apiKey: APIKey.default,
    tools: [Tool(functionDeclarations: [
      FunctionDeclaration(
        name: "controlLight",
        description: "Set the brightness and color temperature of a room light.",
        parameters: [
          "brightness": Schema(
            type: .number,
            format: "double",
            description: "Light level from 0 to 100. Zero is off and 100 is full brightness."
          ),
          "colorTemperature": Schema(
            type: .string,
            format: "enum",
            description: "Color temperature of the light fixture.",
            enumValues: ["daylight", "cool", "warm"]
          ),
        ],
        requiredParameters: ["brightness", "colorTemperature"]
      ),
    ])]
  )

let chat = generativeModel.startChat()

let prompt = "Dim the lights so the room feels cozy and warm."

// Send the message to the model.
let response1 = try await chat.sendMessage(prompt)

// Check if the model responded with a function call.
// For simplicity, this sample uses the first function call found.
guard let functionCall = response1.functionCalls.first else {
  fatalError("Model did not respond with a function call.")
}
// Print an error if the returned function was not declared
guard functionCall.name == "controlLight" else {
  fatalError("Unexpected function called: \(functionCall.name)")
}
// Verify that the names and types of the parameters match the declaration
guard case let .number(brightness) = functionCall.args["brightness"] else {
  fatalError("Missing argument: brightness")
}
guard case let .string(colorTemperature) = functionCall.args["colorTemperature"] else {
  fatalError("Missing argument: colorTemperature")
}

// Call the executable function named in the FunctionCall with the arguments specified in the
// FunctionCall and let it call the hypothetical API.
let apiResponse = controlLight(brightness: brightness, colorTemperature: colorTemperature)

// Send the API response back to the model so it can generate a text response that can be
// displayed to the user.
let response2 = try await chat.sendMessage([ModelContent(
  role: "function",
  parts: [.functionResponse(FunctionResponse(name: "controlLight", response: apiResponse))]
)])

if let text = response2.text {
  print(text)
}

Dart

Map<String, Object?> setLightValues(Map<String, Object?> args) {
  return args;
}

final controlLightFunction = FunctionDeclaration(
    'controlLight',
    'Set the brightness and color temperature of a room light.',
    Schema.object(properties: {
      'brightness': Schema.number(
          description:
              'Light level from 0 to 100. Zero is off and 100 is full brightness.',
          nullable: false),
      'colorTemperatur': Schema.string(
          description:
              'Color temperature of the light fixture which can be `daylight`, `cool`, or `warm`',
          nullable: false),
    }));

final functions = {controlLightFunction.name: setLightValues};
FunctionResponse dispatchFunctionCall(FunctionCall call) {
  final function = functions[call.name]!;
  final result = function(call.args);
  return FunctionResponse(call.name, result);
}

final model = GenerativeModel(
  model: 'gemini-1.5-pro',
  apiKey: apiKey,
  tools: [
    Tool(functionDeclarations: [controlLightFunction])
  ],
);

final prompt = 'Dim the lights so the room feels cozy and warm.';
final content = [Content.text(prompt)];
var response = await model.generateContent(content);

List<FunctionCall> functionCalls;
while ((functionCalls = response.functionCalls.toList()).isNotEmpty) {
  var responses = <FunctionResponse>[
    for (final functionCall in functionCalls)
      dispatchFunctionCall(functionCall)
  ];
  content
    ..add(response.candidates.first.content)
    ..add(Content.functionResponses(responses));
  response = await model.generateContent(content);
}
print('Response: ${response.text}');

Java

FunctionDeclaration multiplyDefinition =
    defineFunction(
        /* name  */ "multiply",
        /* description */ "returns a * b.",
        /* parameters */ Arrays.asList(
            Schema.numDouble("a", "First parameter"),
            Schema.numDouble("b", "Second parameter")),
        /* required */ Arrays.asList("a", "b"));

Tool tool = new Tool(Arrays.asList(multiplyDefinition), null);

// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
    new GenerativeModel(
        /* modelName */ "gemini-1.5-flash",
        // Access your API key as a Build Configuration variable (see "Set up your API key"
        // above)
        /* apiKey */ BuildConfig.apiKey,
        /* generationConfig (optional) */ null,
        /* safetySettings (optional) */ null,
        /* requestOptions (optional) */ new RequestOptions(),
        /* functionDeclarations (optional) */ Arrays.asList(tool));
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

// Create prompt
Content.Builder userContentBuilder = new Content.Builder();
userContentBuilder.setRole("user");
userContentBuilder.addText(
    "I have 57 cats, each owns 44 mittens, how many mittens is that in total?");
Content userMessage = userContentBuilder.build();

// For illustrative purposes only. You should use an executor that fits your needs.
Executor executor = Executors.newSingleThreadExecutor();

// Initialize the chat
ChatFutures chat = model.startChat();

// Send the message
ListenableFuture<GenerateContentResponse> response = chat.sendMessage(userMessage);

Futures.addCallback(
    response,
    new FutureCallback<GenerateContentResponse>() {
      @Override
      public void onSuccess(GenerateContentResponse result) {
        if (!result.getFunctionCalls().isEmpty()) {
          handleFunctionCall(result);
        }
        if (!result.getText().isEmpty()) {
          System.out.println(result.getText());
        }
      }

      @Override
      public void onFailure(Throwable t) {
        t.printStackTrace();
      }

      private void handleFunctionCall(GenerateContentResponse result) {
        FunctionCallPart multiplyFunctionCallPart =
            result.getFunctionCalls().stream()
                .filter(fun -> fun.getName().equals("multiply"))
                .findFirst()
                .get();
        double a = Double.parseDouble(multiplyFunctionCallPart.getArgs().get("a"));
        double b = Double.parseDouble(multiplyFunctionCallPart.getArgs().get("b"));

        try {
          // `multiply(a, b)` is a regular java function defined in another class
          FunctionResponsePart functionResponsePart =
              new FunctionResponsePart(
                  "multiply", new JSONObject().put("result", multiply(a, b)));

          // Create prompt
          Content.Builder functionCallResponse = new Content.Builder();
          userContentBuilder.setRole("user");
          userContentBuilder.addPart(functionResponsePart);
          Content userMessage = userContentBuilder.build();

          chat.sendMessage(userMessage);
        } catch (JSONException e) {
          throw new RuntimeException(e);
        }
      }
    },
    executor);

कॉन्फ़िगरेशन जनरेट करें

Python

model = genai.GenerativeModel("gemini-1.5-flash")
response = model.generate_content(
    "Tell me a story about a magic backpack.",
    generation_config=genai.types.GenerationConfig(
        # Only one candidate for now.
        candidate_count=1,
        stop_sequences=["x"],
        max_output_tokens=20,
        temperature=1.0,
    ),
)

print(response.text)

Node.js

// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
  model: "gemini-1.5-flash",
  generationConfig: {
    candidateCount: 1,
    stopSequences: ["x"],
    maxOutputTokens: 20,
    temperature: 1.0,
  },
});

const result = await model.generateContent(
  "Tell me a story about a magic backpack.",
);
console.log(result.response.text());

शेल

curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
        "contents": [{
            "parts":[
                {"text": "Write a story about a magic backpack."}
            ]
        }],
        "safetySettings": [
            {
                "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
                "threshold": "BLOCK_ONLY_HIGH"
            }
        ],
        "generationConfig": {
            "stopSequences": [
                "Title"
            ],
            "temperature": 1.0,
            "maxOutputTokens": 800,
            "topP": 0.8,
            "topK": 10
        }
    }'  2> /dev/null | grep "text"

Kotlin

val config = generationConfig {
  temperature = 0.9f
  topK = 16
  topP = 0.1f
  maxOutputTokens = 200
  stopSequences = listOf("red")
}

val generativeModel =
    GenerativeModel(
        // Specify a Gemini model appropriate for your use case
        modelName = "gemini-1.5-flash",
        apiKey = BuildConfig.apiKey,
        generationConfig = config)

Swift

let config = GenerationConfig(
  temperature: 0.9,
  topP: 0.1,
  topK: 16,
  candidateCount: 1,
  maxOutputTokens: 200,
  stopSequences: ["red", "orange"]
)

let generativeModel =
  GenerativeModel(
    // Specify a Gemini model appropriate for your use case
    name: "gemini-1.5-flash",
    // Access your API key from your on-demand resource .plist file (see "Set up your API key"
    // above)
    apiKey: APIKey.default,
    generationConfig: config
  )

Dart

final model = GenerativeModel(
  model: 'gemini-1.5-flash',
  apiKey: apiKey,
);
final prompt = 'Tell me a story about a magic backpack.';

final response = await model.generateContent(
  [Content.text(prompt)],
  generationConfig: GenerationConfig(
    candidateCount: 1,
    stopSequences: ['x'],
    maxOutputTokens: 20,
    temperature: 1.0,
  ),
);
print(response.text);

Java

GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.temperature = 0.9f;
configBuilder.topK = 16;
configBuilder.topP = 0.1f;
configBuilder.maxOutputTokens = 200;
configBuilder.stopSequences = Arrays.asList("red");

GenerationConfig generationConfig = configBuilder.build();

// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
    new GenerativeModel("gemini-1.5-flash", BuildConfig.apiKey, generationConfig);

GenerativeModelFutures model = GenerativeModelFutures.from(gm);

सुरक्षा सेटिंग

Python

model = genai.GenerativeModel("gemini-1.5-flash")
unsafe_prompt = "I support Martians Soccer Club and I think Jupiterians Football Club sucks! Write a ironic phrase about them."
response = model.generate_content(
    unsafe_prompt,
    safety_settings={
        "HATE": "MEDIUM",
        "HARASSMENT": "BLOCK_ONLY_HIGH",
    },
)
# If you want to set all the safety_settings to the same value you can just pass that value:
response = model.generate_content(unsafe_prompt, safety_settings="MEDIUM")
try:
    print(response.text)
except:
    print("No information generated by the model.")

print(response.candidates[0].safety_ratings)

Node.js

// Make sure to include these imports:
// import { GoogleGenerativeAI, HarmCategory, HarmBlockThreshold } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
  model: "gemini-1.5-flash",
  safetySettings: [
    {
      category: HarmCategory.HARM_CATEGORY_HARASSMENT,
      threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
    },
    {
      category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
      threshold: HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
    },
  ],
});

const unsafePrompt =
  "I support Martians Soccer Club and I think " +
  "Jupiterians Football Club sucks! Write an ironic phrase telling " +
  "them how I feel about them.";

const result = await model.generateContent(unsafePrompt);

try {
  result.response.text();
} catch (e) {
  console.error(e);
  console.log(result.response.candidates[0].safetyRatings);
}

शेल

echo '{
    "safetySettings": [
        {'category': HARM_CATEGORY_HARASSMENT, 'threshold': BLOCK_ONLY_HIGH},
        {'category': HARM_CATEGORY_HATE_SPEECH, 'threshold': BLOCK_MEDIUM_AND_ABOVE}
    ],
    "contents": [{
        "parts":[{
            "text": "'I support Martians Soccer Club and I think Jupiterians Football Club sucks! Write a ironic phrase about them.'"}]}]}' > request.json

    curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$GOOGLE_API_KEY" \
        -H 'Content-Type: application/json' \
        -X POST \
        -d @request.json  2> /dev/null > response.json

    jq .promptFeedback > response.json

Kotlin

val harassmentSafety = SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.ONLY_HIGH)

val hateSpeechSafety = SafetySetting(HarmCategory.HATE_SPEECH, BlockThreshold.MEDIUM_AND_ABOVE)

val generativeModel =
    GenerativeModel(
        // The Gemini 1.5 models are versatile and work with most use cases
        modelName = "gemini-1.5-flash",
        apiKey = BuildConfig.apiKey,
        safetySettings = listOf(harassmentSafety, hateSpeechSafety))

Swift

let safetySettings = [
  SafetySetting(harmCategory: .dangerousContent, threshold: .blockLowAndAbove),
  SafetySetting(harmCategory: .harassment, threshold: .blockMediumAndAbove),
  SafetySetting(harmCategory: .hateSpeech, threshold: .blockOnlyHigh),
]

let generativeModel =
  GenerativeModel(
    // Specify a Gemini model appropriate for your use case
    name: "gemini-1.5-flash",
    // Access your API key from your on-demand resource .plist file (see "Set up your API key"
    // above)
    apiKey: APIKey.default,
    safetySettings: safetySettings
  )

Dart

final model = GenerativeModel(
  model: 'gemini-1.5-flash',
  apiKey: apiKey,
);
final prompt = 'I support Martians Soccer Club and I think '
    'Jupiterians Football Club sucks! Write an ironic phrase telling '
    'them how I feel about them.';

final response = await model.generateContent(
  [Content.text(prompt)],
  safetySettings: [
    SafetySetting(HarmCategory.harassment, HarmBlockThreshold.medium),
    SafetySetting(HarmCategory.hateSpeech, HarmBlockThreshold.low),
  ],
);
try {
  print(response.text);
} catch (e) {
  print(e);
  for (final SafetyRating(:category, :probability)
      in response.candidates.first.safetyRatings!) {
    print('Safety Rating: $category - $probability');
  }
}

Java

SafetySetting harassmentSafety =
    new SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.ONLY_HIGH);

SafetySetting hateSpeechSafety =
    new SafetySetting(HarmCategory.HATE_SPEECH, BlockThreshold.MEDIUM_AND_ABOVE);

// Specify a Gemini model appropriate for your use case
GenerativeModel gm =
    new GenerativeModel(
        "gemini-1.5-flash",
        BuildConfig.apiKey,
        null, // generation config is optional
        Arrays.asList(harassmentSafety, hateSpeechSafety));

GenerativeModelFutures model = GenerativeModelFutures.from(gm);

सिस्टम के लिए निर्देश

Python

model = genai.GenerativeModel(
    "models/gemini-1.5-flash",
    system_instruction="You are a cat. Your name is Neko.",
)
response = model.generate_content("Good morning! How are you?")
print(response.text)

Node.js

// Make sure to include these imports:
// import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel({
  model: "gemini-1.5-flash",
  systemInstruction: "You are a cat. Your name is Neko.",
});

const prompt = "Good morning! How are you?";

const result = await model.generateContent(prompt);
const response = result.response;
const text = response.text();
console.log(text);

Kotlin

val generativeModel =
    GenerativeModel(
        // Specify a Gemini model appropriate for your use case
        modelName = "gemini-1.5-flash",
        apiKey = BuildConfig.apiKey,
        systemInstruction = content { text("You are a cat. Your name is Neko.") },
    )

Swift

let generativeModel =
  GenerativeModel(
    // Specify a model that supports system instructions, like a Gemini 1.5 model
    name: "gemini-1.5-flash",
    // Access your API key from your on-demand resource .plist file (see "Set up your API key"
    // above)
    apiKey: APIKey.default,
    systemInstruction: ModelContent(role: "system", parts: "You are a cat. Your name is Neko.")
  )

Dart

final model = GenerativeModel(
  model: 'gemini-1.5-flash',
  apiKey: apiKey,
  systemInstruction: Content.system('You are a cat. Your name is Neko.'),
);
final prompt = 'Good morning! How are you?';

final response = await model.generateContent([Content.text(prompt)]);
print(response.text);

Java

GenerativeModel model =
    new GenerativeModel(
        // Specify a Gemini model appropriate for your use case
        /* modelName */ "gemini-1.5-flash",
        /* apiKey */ BuildConfig.apiKey,
        /* generationConfig (optional) */ null,
        /* safetySettings (optional) */ null,
        /* requestOptions (optional) */ new RequestOptions(),
        /* tools (optional) */ null,
        /* toolsConfig (optional) */ null,
        /* systemInstruction (optional) */ new Content.Builder()
            .addText("You are a cat. Your name is Neko.")
            .build());

जवाब का मुख्य भाग

कामयाब रहने पर, जवाब के मुख्य हिस्से में GenerateContentResponse का एक इंस्टेंस शामिल किया जाता है.

तरीका: TunModels.create

यह ट्यून किया जाने वाला मॉडल बनाता है. इंटरमीडिएट ट्यूनिंग की प्रोग्रेस (अगर कोई है) को google.longrunning.Operations सेवा के ज़रिए ऐक्सेस किया जाता है.

ऑपरेशन सेवा के ज़रिए स्थिति और नतीजों को ऐक्सेस किया जा सकता है. उदाहरण: GET /v1/tunedModels/az2mb0bpw6i/operations/000-111-222

एंडपॉइंट

पोस्ट https://generativelanguage.googleapis.com/v1beta/tunedModels

क्वेरी पैरामीटर

tunedModelId string

ज़रूरी नहीं. अगर बताया गया है, तो ट्यून किए जाने वाले मॉडल के लिए यूनीक आईडी. यह वैल्यू ज़्यादा से ज़्यादा 40 वर्णों की होनी चाहिए. पहला वर्ण कोई अक्षर होना चाहिए और आखिरी वर्ण कोई अक्षर या संख्या हो सकती है. आईडी रेगुलर एक्सप्रेशन से मेल खाना चाहिए: a-z?.

अनुरोध का मुख्य भाग

अनुरोध के मुख्य भाग में TunedModel का उदाहरण है.

अनुरोध का उदाहरण

Python

import time

base_model = "models/gemini-1.0-pro-001"
training_data = [
    {"text_input": "1", "output": "2"},
    # ... more examples ...
    # ...
    {"text_input": "seven", "output": "eight"},
]
operation = genai.create_tuned_model(
    # You can use a tuned model here too. Set `source_model="tunedModels/..."`
    display_name="increment",
    source_model=base_model,
    epoch_count=20,
    batch_size=4,
    learning_rate=0.001,
    training_data=training_data,
)

for status in operation.wait_bar():
    time.sleep(10)

result = operation.result()
print(result)
# # You can plot the loss curve with:
# snapshots = pd.DataFrame(result.tuning_task.snapshots)
# sns.lineplot(data=snapshots, x='epoch', y='mean_loss')

model = genai.GenerativeModel(model_name=result.name)
result = model.generate_content("III")
print(result.text)  # IV

जवाब का मुख्य भाग

यह संसाधन, लंबे समय तक चलने वाली कार्रवाई को दिखाता है, जो कि नेटवर्क एपीआई कॉल की वजह से होती है.

अगर एपीआई सही से जुड़ जाता है, ताे जवाब के मुख्य भाग में नीचे दिए गए स्ट्रक्चर शामिल होता है.

फ़ील्ड
name string

सर्वर का असाइन किया गया नाम. यह नाम सिर्फ़ उस सेवा के लिए यूनीक होता है जिससे वह मूल रूप से मैच करता है. अगर आपने डिफ़ॉल्ट एचटीटीपी मैपिंग का इस्तेमाल किया है, तो name, संसाधन का नाम होना चाहिए जिसके आखिर में operations/{unique_id} हो.

metadata object

ऑपरेशन से जुड़ा खास सेवा का मेटाडेटा. आम तौर पर, इसमें गेम की प्रोग्रेस की जानकारी और सामान्य मेटाडेटा शामिल होता है. जैसे, वीडियो बनाने का समय. ऐसा हो सकता है कि कुछ सेवाएं इस तरह का मेटाडेटा उपलब्ध न कराएं. लंबे समय तक चलने वाली कार्रवाई दिखाने वाले किसी भी तरीके में, अगर कोई है, तो मेटाडेटा टाइप का दस्तावेज़ होना चाहिए.

ऐसा ऑब्जेक्ट जिसमें आर्बिट्रेरी टाइप के फ़ील्ड शामिल होते हैं. अतिरिक्त फ़ील्ड "@type" में, टाइप की पहचान करने वाला यूआरआई होता है. उदाहरण: { "id": 1234, "@type": "types.example.com/standard/id" }.

done boolean

अगर वैल्यू false है, तो इसका मतलब है कि कार्रवाई अब भी चल रही है. अगर true है, तो कार्रवाई पूरी हो गई है और error या response उपलब्ध है.

यूनियन फ़ील्ड result. कार्रवाई का नतीजा, जो कोई error या मान्य response हो सकता है. अगर done == false है, तो error या response में से कोई भी वैल्यू सेट नहीं होती. अगर done == true है, तो error या response में से किसी एक को सेट किया जा सकता है. ऐसा हो सकता है कि कुछ सेवाएं नतीजे न दिखा पाएं. result इनमें से सिर्फ़ एक हो सकता है:
error object (Status)

कार्रवाई न हो पाने या रद्द करने की स्थिति में, कार्रवाई का नतीजा.

response object

कार्रवाई का सामान्य, सफल रिस्पॉन्स. अगर ओरिजनल तरीके से कोई डेटा नहीं मिलता है जैसे कि Delete, तो रिस्पॉन्स google.protobuf.Empty होगा. अगर मूल तरीका स्टैंडर्ड Get/Create/Update है, तो जवाब संसाधन होना चाहिए. दूसरे तरीकों के लिए, जवाब XxxResponse टाइप होना चाहिए, जिसमें Xxx मूल तरीके का नाम है. उदाहरण के लिए, अगर मूल तरीके का नाम TakeSnapshot() है, तो अनुमानित रिस्पॉन्स टाइप TakeSnapshotResponse होता है.

ऐसा ऑब्जेक्ट जिसमें आर्बिट्रेरी टाइप के फ़ील्ड शामिल होते हैं. अतिरिक्त फ़ील्ड "@type" में, टाइप की पहचान करने वाला यूआरआई होता है. उदाहरण: { "id": 1234, "@type": "types.example.com/standard/id" }.

JSON के काेड में दिखाना
{
  "name": string,
  "metadata": {
    "@type": string,
    field1: ...,
    ...
  },
  "done": boolean,

  // Union field result can be only one of the following:
  "error": {
    object (Status)
  },
  "response": {
    "@type": string,
    field1: ...,
    ...
  }
  // End of list of possible types for union field result.
}

तरीका: TunerModels.get

किसी चुनिंदा TunedModel के बारे में जानकारी मिलती है.

एंडपॉइंट

पाएं https://generativelanguage.googleapis.com/v1beta/{name=tunedModels/*}

पाथ पैरामीटर

name string

ज़रूरी है. मॉडल के संसाधन का नाम.

फ़ॉर्मैट: tunedModels/my-model-id यह tunedModels/{tunedmodel} का रूप लेता है.

अनुरोध का मुख्य भाग

अनुरोध का मुख्य हिस्सा खाली होना चाहिए.

अनुरोध का उदाहरण

Python

model_info = genai.get_model("tunedModels/my-increment-model")
print(model_info)

जवाब का मुख्य भाग

कामयाब रहने पर, जवाब के मुख्य हिस्से में TunedModel का एक इंस्टेंस शामिल किया जाता है.

तरीका: TunerModels.list

यह उपयोगकर्ता के ट्यून किए गए मॉडल की सूची बनाता है.

एंडपॉइंट

पाएं https://generativelanguage.googleapis.com/v1beta/tunedModels

क्वेरी पैरामीटर

pageSize integer

ज़रूरी नहीं. ज़्यादा से ज़्यादा TunedModels आइटम लौटाए जा सकते हैं (हर पेज के हिसाब से). यह सेवा, ट्यून किए जाने वाले मॉडल की संख्या कम कर सकती है.

अगर जानकारी उपलब्ध नहीं है, तो ट्यून किए जाने वाले ज़्यादा से ज़्यादा 10 मॉडल दिखाए जाएंगे. इस तरीके से हर पेज पर ज़्यादा से ज़्यादा 1,000 मॉडल दिखाए जाते हैं, भले ही आपने बड़ा pageSize को पास किया हो.

pageToken string

ज़रूरी नहीं. पिछले tunedModels.list कॉल से मिला पेज टोकन.

अगला पेज वापस पाने के लिए, अगले अनुरोध के लिए तर्क के तौर पर, एक अनुरोध के बाद मिले pageToken को उपलब्ध कराएं.

पेजों पर नंबर डालते समय, tunedModels.list को दिए गए अन्य सभी पैरामीटर, पेज टोकन देने वाले कॉल से मैच होने चाहिए.

filter string

ज़रूरी नहीं. फ़िल्टर, ट्यून किए गए मॉडल की जानकारी और डिसप्ले नेम के लिए की गई खोज का पूरा टेक्स्ट होता है. डिफ़ॉल्ट रूप से, नतीजों में ट्यून किए जाने वाले ऐसे मॉडल शामिल नहीं होंगे जिन्हें सभी लोगों के साथ शेयर किया गया हो.

अतिरिक्त ऑपरेटर: - owner:me - लेखकs:me -reader:me - reader:सभी

उदाहरण: "owner:me" ट्यून किए जाने वाले उन सभी मॉडल की जानकारी देता है जिनमें कॉलर के मालिक की भूमिका "readers:me" है ट्यून किए जाने वाले सभी ऐसे मॉडल दिखाता है जिनमें कॉलर की भूमिका "readers:सभी" होती है ट्यून किए गए ऐसे सभी मॉडल दिखाता है जिन्हें सभी के साथ शेयर किया गया है

अनुरोध का मुख्य भाग

अनुरोध का मुख्य हिस्सा खाली होना चाहिए.

अनुरोध का उदाहरण

Python

for model_info in genai.list_tuned_models():
    print(model_info.name)

जवाब का मुख्य भाग

tunedModels.list से मिले जवाब में, मॉडल की पेजों वाली सूची शामिल है.

अगर एपीआई सही से जुड़ जाता है, ताे जवाब के मुख्य भाग में नीचे दिए गए स्ट्रक्चर शामिल होता है.

फ़ील्ड
tunedModels[] object (TunedModel)

लौटाए गए मॉडल.

nextPageToken string

एक टोकन, जिसे अगला पेज फिर से पाने के लिए pageToken के तौर पर भेजा जा सकता है.

अगर इस फ़ील्ड को छोड़ दिया जाता है, तो और पेज नहीं होते हैं.

JSON के काेड में दिखाना
{
  "tunedModels": [
    {
      object (TunedModel)
    }
  ],
  "nextPageToken": string
}

तरीका: TunerModels.patch

ट्यून किए गए मॉडल को अपडेट करता है.

एंडपॉइंट

पैच https://generativelanguage.googleapis.com/v1beta/{tunedModel.name=tunedModels/*}

PATCH https://generativelanguage.googleapis.com/v1beta/{tunedModel.name=tunedModels/*}

पाथ पैरामीटर

tunedModel.name string

सिर्फ़ आउटपुट के लिए. ट्यून किए गए मॉडल का नाम. बनाने पर, एक यूनीक नाम जनरेट होगा. उदाहरण: tunedModels/az2mb0bpw6i अगर DisplayName को बनाते समय सेट किया गया है, तो नाम के आईडी वाला हिस्सा सेट करने के लिए, DisplayName के शब्दों को हाइफ़न के साथ जोड़ा जाएगा. इसके बाद, यूनीक वैल्यू के लिए कोई भी हिस्सा बिना किसी खास क्रम के जोड़ा जाएगा. उदाहरण: displayName = "वाक्य का अनुवाद करने वाले" name = "tunedModels/sentence-Translator-u3b7m" यह tunedModels/{tunedmodel} का रूप लेता है.

क्वेरी पैरामीटर

updateMask string (FieldMask format)

ज़रूरी है. अपडेट किए जाने वाले फ़ील्ड की सूची.

यह फ़ील्ड के पूरी तरह क्वालिफ़ाइड नाम की सूची है, जिसे कॉमा लगाकर अलग किया गया है. उदाहरण: "user.displayName,photo".

अनुरोध का मुख्य भाग

अनुरोध के मुख्य भाग में TunedModel का उदाहरण है.

जवाब का मुख्य भाग

कामयाब रहने पर, जवाब के मुख्य हिस्से में TunedModel का एक इंस्टेंस शामिल किया जाता है.

तरीका: TunerModels.delete

ट्यून किए गए मॉडल को मिटाता है.

एंडपॉइंट

मिटाएं https://generativelanguage.googleapis.com/v1beta/{name=tunedModels/*}

पाथ पैरामीटर

name string

ज़रूरी है. मॉडल के संसाधन का नाम. फ़ॉर्मैट: tunedModels/my-model-id यह tunedModels/{tunedmodel} का रूप लेता है.

अनुरोध का मुख्य भाग

अनुरोध का मुख्य हिस्सा खाली होना चाहिए.

जवाब का मुख्य भाग

जवाब सही होने पर, जवाब का मुख्य हिस्सा खाली होता है.

REST संसाधन: ट्यून किए गए मॉडल

संसाधन: TunedModel

ModelService.CreateTunedModel का इस्तेमाल करके बनाया गया बेहतर मॉडल.

JSON के काेड में दिखाना
{
  "name": string,
  "displayName": string,
  "description": string,
  "state": enum (State),
  "createTime": string,
  "updateTime": string,
  "tuningTask": {
    object (TuningTask)
  },

  // Union field source_model can be only one of the following:
  "tunedModelSource": {
    object (TunedModelSource)
  },
  "baseModel": string
  // End of list of possible types for union field source_model.
  "temperature": number,
  "topP": number,
  "topK": integer
}
फ़ील्ड
name string

सिर्फ़ आउटपुट के लिए. ट्यून किए गए मॉडल का नाम. बनाने पर, एक यूनीक नाम जनरेट होगा. उदाहरण: tunedModels/az2mb0bpw6i अगर DisplayName को बनाते समय सेट किया गया है, तो नाम के आईडी वाला हिस्सा सेट करने के लिए, DisplayName के शब्दों को हाइफ़न के साथ जोड़ा जाएगा. इसके बाद, यूनीक वैल्यू के लिए कोई भी हिस्सा बिना किसी खास क्रम के जोड़ा जाएगा. उदाहरण: displayName = "वाक्य का अनुवाद करने वाले" name = "tunedModels/sentence-Translator-u3b7m"

displayName string

ज़रूरी नहीं. यूज़र इंटरफ़ेस में इस मॉडल के लिए दिखाया जाने वाला नाम. डिसप्ले नेम ज़्यादा से ज़्यादा 40 वर्णों का होना चाहिए. इसमें स्पेस भी शामिल हैं.

description string

ज़रूरी नहीं. इस मॉडल के बारे में कम शब्दों में जानकारी.

state enum (State)

सिर्फ़ आउटपुट के लिए. ट्यून किए गए मॉडल की स्थिति.

createTime string (Timestamp format)

सिर्फ़ आउटपुट के लिए. इस मॉडल को बनाए जाने के समय का टाइमस्टैंप.

आरएफ़सी3339 यूटीसी "ज़ुलु" में टाइमस्टैंप फ़ॉर्मैट, नैनोसेकंड रिज़ॉल्यूशन और ज़्यादा से ज़्यादा नौ फ़्रैक्शनल अंकों के साथ हो सकता है. उदाहरण: "2014-10-02T15:01:23Z" और "2014-10-02T15:01:23.045123456Z".

updateTime string (Timestamp format)

सिर्फ़ आउटपुट के लिए. इस मॉडल को अपडेट किए जाने के समय का टाइमस्टैंप.

आरएफ़सी3339 यूटीसी "ज़ुलु" में टाइमस्टैंप फ़ॉर्मैट, नैनोसेकंड रिज़ॉल्यूशन और ज़्यादा से ज़्यादा नौ फ़्रैक्शनल अंकों के साथ हो सकता है. उदाहरण: "2014-10-02T15:01:23Z" और "2014-10-02T15:01:23.045123456Z".

tuningTask object (TuningTask)

ज़रूरी है. ट्यूनिंग करने वाला टास्क, जो ट्यून किया जाने वाला मॉडल बनाता है.

यूनियन फ़ील्ड source_model. ट्यूनिंग के लिए शुरुआती पॉइंट के तौर पर इस्तेमाल किया जाने वाला मॉडल. source_model इनमें से सिर्फ़ एक हो सकता है:
tunedModelSource object (TunedModelSource)

ज़रूरी नहीं. ट्यून किए गए मॉडल का इस्तेमाल, नए मॉडल की ट्रेनिंग के लिए शुरुआती पॉइंट के तौर पर किया जा सकता है.

baseModel string

इम्यूटेबल. ट्यून करने के लिए Model का नाम. उदाहरण: models/text-bison-001

temperature number

ज़रूरी नहीं. इससे आउटपुट की रैंडमनेस को कंट्रोल किया जाता है.

वैल्यू [0.0,1.0] से ज़्यादा भी हो सकती है. इसमें ये वैल्यू भी शामिल हैं. 1.0 के करीब की वैल्यू, ज़्यादा अलग-अलग तरह के जवाब देगी. वहीं, 0.0 के करीब की वैल्यू, आम तौर पर इस मॉडल से मिलने वाले चौंकाने वाले जवाब नहीं देगी.

यह वैल्यू, मॉडल बनाते समय डिफ़ॉल्ट तौर पर बेस मॉडल में इस्तेमाल होने वाली वैल्यू तय करती है.

topP number

ज़रूरी नहीं. न्यूक्लियस सैंपलिंग के लिए.

न्यूक्लियस सैंपलिंग के तहत टोकन के सबसे छोटे सेट को शामिल किया जाता है, जिसकी संभावना का योग कम से कम topP होता है.

यह वैल्यू, मॉडल बनाते समय डिफ़ॉल्ट तौर पर बेस मॉडल में इस्तेमाल होने वाली वैल्यू तय करती है.

topK integer

ज़रूरी नहीं. टॉप-के सैंपलिंग के लिए.

टॉप-K सैंपलिंग, topK के सबसे संभावित टोकन के सेट के हिसाब से काम करती है. यह वैल्यू तय करती है कि मॉडल को कॉल करते समय, बैकएंड में डिफ़ॉल्ट तौर पर इसका इस्तेमाल किया जाए या नहीं.

यह वैल्यू, मॉडल बनाते समय डिफ़ॉल्ट तौर पर बेस मॉडल में इस्तेमाल होने वाली वैल्यू तय करती है.

TunedModelSource

मॉडल को नए मॉडल की ट्रेनिंग के लिए, सोर्स के तौर पर जोड़ा गया.

JSON के काेड में दिखाना
{
  "tunedModel": string,
  "baseModel": string
}
फ़ील्ड
tunedModel string

इम्यूटेबल. नए मॉडल को ट्रेनिंग देने के लिए, शुरुआती पॉइंट के तौर पर इस्तेमाल किया जाने वाला TunedModel का नाम. उदाहरण: tunedModels/my-tuned-model

baseModel string

सिर्फ़ आउटपुट के लिए. उस बेस का नाम Model जिससे यह TunedModel ट्यून किया गया था. उदाहरण: models/text-bison-001

स्थिति

ट्यून किए गए मॉडल की स्थिति.

Enums
STATE_UNSPECIFIED डिफ़ॉल्ट वैल्यू. इस वैल्यू का इस्तेमाल नहीं किया गया है.
CREATING मॉडल बनाया जा रहा है.
ACTIVE यह मॉडल इस्तेमाल के लिए तैयार है.
FAILED मॉडल बनाया नहीं जा सका.

TuningTask

ऐसे टास्क ट्यून किए जा रहे हैं जो ट्यून किए जाने वाले मॉडल बनाते हैं.

JSON के काेड में दिखाना
{
  "startTime": string,
  "completeTime": string,
  "snapshots": [
    {
      object (TuningSnapshot)
    }
  ],
  "trainingData": {
    object (Dataset)
  },
  "hyperparameters": {
    object (Hyperparameters)
  }
}
फ़ील्ड
startTime string (Timestamp format)

सिर्फ़ आउटपुट के लिए. इस मॉडल को ट्यून करने के दौरान दिखने वाला टाइमस्टैंप.

आरएफ़सी3339 यूटीसी "ज़ुलु" में टाइमस्टैंप फ़ॉर्मैट, नैनोसेकंड रिज़ॉल्यूशन और ज़्यादा से ज़्यादा नौ फ़्रैक्शनल अंकों के साथ हो सकता है. उदाहरण: "2014-10-02T15:01:23Z" और "2014-10-02T15:01:23.045123456Z".

completeTime string (Timestamp format)

सिर्फ़ आउटपुट के लिए. इस मॉडल को ट्यून करने के दौरान दिखने वाला टाइमस्टैंप.

आरएफ़सी3339 यूटीसी "ज़ुलु" में टाइमस्टैंप फ़ॉर्मैट, नैनोसेकंड रिज़ॉल्यूशन और ज़्यादा से ज़्यादा नौ फ़्रैक्शनल अंकों के साथ हो सकता है. उदाहरण: "2014-10-02T15:01:23Z" और "2014-10-02T15:01:23.045123456Z".

snapshots[] object (TuningSnapshot)

सिर्फ़ आउटपुट के लिए. ट्यूनिंग के दौरान इकट्ठा की गई मेट्रिक.

trainingData object (Dataset)

ज़रूरी है. सिर्फ़ इनपुट. इम्यूटेबल. मॉडल ट्रेनिंग डेटा.

hyperparameters object (Hyperparameters)

इम्यूटेबल. ट्यूनिंग प्रोसेस को कंट्रोल करने वाले हाइपर पैरामीटर. अगर यह पैरामीटर उपलब्ध नहीं है, तो डिफ़ॉल्ट वैल्यू का इस्तेमाल किया जाएगा.

TuningSnapshot

एक ट्यूनिंग स्टेप के लिए रिकॉर्ड करें.

JSON के काेड में दिखाना
{
  "step": integer,
  "epoch": integer,
  "meanLoss": number,
  "computeTime": string
}
फ़ील्ड
step integer

सिर्फ़ आउटपुट के लिए. ट्यूनिंग स्टेप.

epoch integer

सिर्फ़ आउटपुट के लिए. वह युग, जिसका यह चरण हिस्सा था.

meanLoss number

सिर्फ़ आउटपुट के लिए. इस चरण के लिए ट्रेनिंग के उदाहरणों का औसत नुकसान.

computeTime string (Timestamp format)

सिर्फ़ आउटपुट के लिए. इस मेट्रिक को कैलकुलेट करते समय दिखने वाला टाइमस्टैंप.

आरएफ़सी3339 यूटीसी "ज़ुलु" में टाइमस्टैंप फ़ॉर्मैट, नैनोसेकंड रिज़ॉल्यूशन और ज़्यादा से ज़्यादा नौ फ़्रैक्शनल अंकों के साथ हो सकता है. उदाहरण: "2014-10-02T15:01:23Z" और "2014-10-02T15:01:23.045123456Z".

डेटासेट

ट्रेनिंग या पुष्टि के लिए डेटासेट.

JSON के काेड में दिखाना
{

  // Union field dataset can be only one of the following:
  "examples": {
    object (TuningExamples)
  }
  // End of list of possible types for union field dataset.
}
फ़ील्ड यूनियन फ़ील्ड dataset. इनलाइन डेटा या डेटा का रेफ़रंस. dataset इनमें से सिर्फ़ एक हो सकता है:
examples object (TuningExamples)

ज़रूरी नहीं. इनलाइन उदाहरण.

TuningExamples

ट्यूनिंग के उदाहरणों का सेट. यह ट्रेनिंग या पुष्टि करने वाला डेटा हो सकता है.

JSON के काेड में दिखाना
{
  "examples": [
    {
      object (TuningExample)
    }
  ]
}
फ़ील्ड
examples[] object (TuningExample)

ज़रूरी है. उदाहरण. उदाहरण के तौर पर दिया गया इनपुट, टेक्स्ट या चर्चा के लिए हो सकता है. हालांकि, किसी सेट में मौजूद सभी उदाहरण एक ही तरह के होने चाहिए.

TuningExample

ट्यूनिंग के लिए एक उदाहरण.

JSON के काेड में दिखाना
{
  "output": string,

  // Union field model_input can be only one of the following:
  "textInput": string
  // End of list of possible types for union field model_input.
}
फ़ील्ड
output string

ज़रूरी है. अनुमानित मॉडल आउटपुट.

यूनियन फ़ील्ड model_input. इस उदाहरण के लिए मॉडल के लिए इनपुट. model_input इनमें से सिर्फ़ एक हो सकता है:
textInput string

ज़रूरी नहीं. टेक्स्ट मॉडल इनपुट.

हाइपर पैरामीटर

ट्यूनिंग प्रोसेस को कंट्रोल करने वाले हाइपर पैरामीटर. ज़्यादा जानकारी के लिए, https://ai.google.dev/docs/model_tuning_guidance पर जाएं

JSON के काेड में दिखाना
{

  // Union field learning_rate_option can be only one of the following:
  "learningRate": number,
  "learningRateMultiplier": number
  // End of list of possible types for union field learning_rate_option.
  "epochCount": integer,
  "batchSize": integer
}
फ़ील्ड यूनियन फ़ील्ड learning_rate_option. ट्यूनिंग के दौरान लर्निंग रेट की जानकारी देने के विकल्प. learning_rate_option इनमें से सिर्फ़ एक हो सकता है:
learningRate number

ज़रूरी नहीं. इम्यूटेबल. ट्यूनिंग के लिए, लर्निंग रेट हाइपर पैरामीटर. अगर यह नीति सेट नहीं है, तो ट्रेनिंग के उदाहरणों की संख्या के आधार पर, 0.001 या 0.0002 की डिफ़ॉल्ट वैल्यू का हिसाब लगाया जाएगा.

learningRateMultiplier number

ज़रूरी नहीं. इम्यूटेबल. लर्निंग रेट मल्टीप्लायर का इस्तेमाल, डिफ़ॉल्ट (सुझाई गई) वैल्यू के आधार पर फ़ाइनल लर्निंग रेट का हिसाब लगाने के लिए किया जाता है. सीखने की असल दर := LearningRateमल्टीपैक * सीखने की डिफ़ॉल्ट दर, सीखने की डिफ़ॉल्ट दर, बेस मॉडल और डेटासेट के साइज़ पर निर्भर करती है. इस नीति को सेट न करने पर, डिफ़ॉल्ट वैल्यू 1.0 का इस्तेमाल किया जाता है.

epochCount integer

इम्यूटेबल. ट्रेनिंग के युगों की संख्या. epoch का मतलब है कि ट्रेनिंग डेटा को एक बार में ही प्रोसेस कर दिया जाता है. अगर यह नीति सेट नहीं है, तो डिफ़ॉल्ट वैल्यू 5 का इस्तेमाल किया जाएगा.

batchSize integer

इम्यूटेबल. ट्यूनिंग के लिए बैच साइज़ हाइपर पैरामीटर. अगर यह नीति सेट नहीं है, तो ट्रेनिंग के उदाहरणों की संख्या के आधार पर, डिफ़ॉल्ट वैल्यू 4 या 16 का इस्तेमाल किया जाएगा.