tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > Gemini Controlled Generation

Gemini Controlled Generation

Author: Venkata Sudhakar

Gemini Controlled Generation lets you fine-tune how the model produces output by adjusting temperature, stop sequences, candidate count, and token limits. These parameters give precise control over response creativity, length, and format - essential when building consistent, production-grade applications. ShopMax India uses controlled generation to ensure product descriptions and customer responses meet strict formatting standards.

The GenerationConfig object is passed to generate_content calls. Temperature controls randomness (0 = deterministic, 1 = creative), max_output_tokens caps response length, stop_sequences halt generation at defined markers, and candidate_count returns multiple response options for comparison.

The below example shows how to use temperature and max_output_tokens to generate concise, consistent product descriptions.


It gives the following output,

Factual description:
The Samsung 55 inch 4K UHD Smart TV delivers stunning picture clarity with HDR support and a built-in smart platform for streaming popular Indian OTT apps. Priced at Rs 45,000 at ShopMax India, it is ideal for living rooms and supports dual-band Wi-Fi for reliable connectivity.
Tokens used: 287

The below example shows stop sequences and candidate_count - generating multiple tagline options and stopping at a defined marker.


It gives the following output,

Generated tagline options:
1. Upgrade your home with ShopMax India  -  unbeatable prices, delivered to your door.
2. The best electronics deals in India, only at ShopMax.
3. ShopMax India: Where every rupee gets you more.

ShopMax India uses temperature 0.1 for customer support responses where consistency matters, and temperature 0.8 for marketing copy generation where variety is valued. Stop sequences prevent agents from generating beyond the required answer, reducing token costs by up to 30% on high-volume batch operations across the product catalogue.


 
  


  
bl  br