Gemini Text Generation
Generate content using Google's Gemini API through executable scripts with advanced capabilities including system instructions, thinking mode, JSON output, and Google Search grounding.
When to Use This Skill
Use this skill when you need to:
- Generate any type of text content (blogs, emails, code, stories)
- Process images with text descriptions or analysis
- Perform complex reasoning requiring step-by-step thinking
- Get structured JSON outputs for data processing
- Access real-time information via Google Search
- Apply specific personas or behavior patterns
- Combine text generation with other Gemini skills (images, TTS, embeddings)
Available Scripts
scripts/generate.py
Purpose: Full-featured text generation with all Gemini capabilities
When to use:
- Any text generation task
- Multimodal prompts (text + image)
- Complex reasoning requiring thinking mode
- Structured JSON output requirements
- Real-time information needs (grounding)
- Custom system instructions/personas
Key parameters:
| Parameter |
Description |
Example |
prompt |
Text prompt (required) |
"Explain quantum computing" |
--model, -m |
Model to use |
gemini-3-flash-preview |
--system, -s |
System instruction |
"You are a helpful assistant" |
--thinking, -t |
Enable thinking mode |
Flag |
--json, -j |
Force JSON output |
Flag |
--grounding, -g |
Enable Google Search |
Flag |
--image, -i |
Image for multimodal |
photo.png |
--temperature |
Sampling 0.0-2.0 |
0.7 for creative |
--max-tokens |
Output limit |
1000 |
Output: Generated text string, optionally with grounding sources
Workflows
Workflow 1: Basic Text Generation
python scripts/generate.py "Explain quantum computing in simple terms"
- Best for: Simple content creation, explanations, summaries
- Model:
gemini-3-flash-preview (default, fast)
Workflow 2: With System Instruction (Persona)
python scripts/generate.py "How do I read a file in Python?" --system "You are a helpful coding assistant"
- Best for: Domain-specific tasks, expert personas, consistent tone
- Use when: You need specific behavioral constraints
Workflow 3: Complex Reasoning (Thinking Mode)
python scripts/generate.py "Analyze the ethical implications of AI in healthcare" --thinking
- Best for: Complex analysis, step-by-step reasoning, multi-step problems
- Use when: Task requires careful consideration and logical progression
Workflow 4: Structured JSON Output
python scripts/generate.py "Generate a user profile object with name, email, and preferences" --json
- Best for: Data extraction, structured data generation, API responses
- Output: Valid JSON ready for parsing
- Note: Prompt must clearly request JSON structure
Workflow 5: Real-Time Information (Grounding)
python scripts/generate.py "Who won the latest Super Bowl?" --grounding
- Best for: Current events, news, factual information after training cutoff
- Output: Response + grounding sources with citations
- Use when: Accuracy of current information is critical
Workflow 6: Multimodal (Image Analysis)
python scripts/generate.py "Describe what's in this image in detail" --image photo.png
- Best for: Image captioning, visual analysis, image-based Q&A
- Requires: Image file in PNG or JPEG format
- Combines well with: gemini-files for file upload
Workflow 7: Content Creation Pipeline (Batch + Text + TTS)
# 1. Create batch requests (gemini-batch skill)
# 2. Generate content
python scripts/generate.py "Create a 500-word blog post about sustainable energy"
# 3. Convert to audio (gemini-tts skill)
- Best for: High-volume content production, podcasts, audiobooks
Parameters Reference
Model Selection
| Model |
Speed |
Intelligence |
Context |
Best For |
gemini-3-flash-preview |
Fast |
High |
1M |
General use, agentic tasks (default) |
gemini-3-pro-preview |
Medium |
Highest |
1M |
Complex reasoning, research |
gemini-2.5-flash |
Fast |
Medium |
1M |
Stable, reliable generation |
gemini-2.5-pro |
Slow |
High |
1M |
Code, math, STEM tasks |
Temperature Settings
| Value |
Creativity |
Best For |
| 0.0-0.3 |
Low |
Code, facts, formal writing |
| 0.4-0.7 |
Medium |
Balanced output |
| 0.8-1.0 |
High |
Creative writing, brainstorming |
| 1.0-2.0 |
Very High |
Highly creative, varied outputs |
Thinking Budget
| Value |
Description |
| 0 |
Disabled (default behavior) |
| 512-1024 |
Standard reasoning |
| 2048+ |
Deep analysis (slower, more tokens) |
Output Interpretation
Standard Text Output
- Plain text response ready for use
- Check for truncation if max-tokens was set
- May include markdown formatting
JSON Output
- Valid JSON object (use
--json flag)
- Parse with:
import json; data = json.loads(output)
- Verify structure matches your requirements
- Handle potential parsing errors
Grounded Response
When --grounding is used, the script prints:
- Main response text
- "--- Grounding Sources ---" section
- List of sources with titles and URLs
Thinking Mode Output
- May include reasoning steps before final answer
- Longer response times due to thinking process
- Better for tasks requiring careful analysis
Common Issues
"google-genai not installed"
pip install google-genai
"API key not set"
Set environment variable:
export GOOGLE_API_KEY="your-key-here"
# or
export GEMINI_API_KEY="your-key-here"
"Model not available"
- Check model name spelling
- Verify API access for selected model
- Try
gemini-3-flash-preview (most available)
JSON parse errors
- Ensure prompt explicitly requests JSON structure
- Check output for JSON formatting
- Consider using system instruction: "You always respond with valid JSON"
Image file not found
- Verify image path is correct
- Use absolute paths if relative paths fail
- Supported formats: PNG, JPEG
Response truncated
- Increase
--max-tokens value
- Break task into smaller requests
- Use pro models with higher token limits
Best Practices
Performance Optimization
- Use flash models for speed, pro for quality
- Lower temperature (0.0-0.3) for deterministic outputs
- Set appropriate max-tokens to control costs
- Use thinking mode only for complex tasks
Prompt Engineering
- Be specific and clear in your prompts
- Use system instructions for consistent behavior
- Include examples in prompts for better results
- For JSON: specify exact structure in prompt
Error Handling
- Wrap script calls in try-except blocks
- Validate JSON output before parsing
- Handle network timeouts with retries
- Check API quota limits for batch operations
Cost Management
- Use flash models when possible (lower cost)
- Limit max-tokens for simple queries
- Cache results for repeated queries
- Use batch API for high-volume tasks
Related Skills
- gemini-image: Generate images from text
- gemini-tts: Convert text to speech
- gemini-embeddings: Create vector embeddings for semantic search
- gemini-files: Upload files for multimodal processing
- gemini-batch: Process multiple requests efficiently
Quick Reference
# Basic
python scripts/generate.py "Your prompt"
# Persona
python scripts/generate.py "Prompt" --system "You are X"
# Thinking
python scripts/generate.py "Complex task" --thinking
# JSON
python scripts/generate.py "Generate JSON" --json
# Search
python scripts/generate.py "Current event" --grounding
# Multimodal
python scripts/generate.py "Describe this" --image photo.png
Reference
1---2name: gemini-text3description: Generate text content using Google Gemini models via scripts/. Use for text generation, multimodal prompts with images, thinking mode for complex reasoning, JSON-formatted outputs, and Google Search grounding for real-time information. Triggers on "generate with gemini", "use gemini for text", "AI text generation", "multimodal prompt", "gemini thinking mode", "grounded response".4license: MIT5---6
7# Gemini Text Generation
8
9Generate content using Google's Gemini API through executable scripts with advanced capabilities including system instructions, thinking mode, JSON output, and Google Search grounding.
10
11## When to Use This Skill
12
13Use this skill when you need to:
14- Generate any type of text content (blogs, emails, code, stories)
15- Process images with text descriptions or analysis
16- Perform complex reasoning requiring step-by-step thinking
17- Get structured JSON outputs for data processing
18- Access real-time information via Google Search
19- Apply specific personas or behavior patterns
20- Combine text generation with other Gemini skills (images, TTS, embeddings)
21
22## Available Scripts
23
24### scripts/generate.py
25**Purpose**: Full-featured text generation with all Gemini capabilities
26
27**When to use**:
28- Any text generation task
29- Multimodal prompts (text + image)
30- Complex reasoning requiring thinking mode
31- Structured JSON output requirements
32- Real-time information needs (grounding)
33- Custom system instructions/personas
34
35**Key parameters**:
36| Parameter | Description | Example |
37|-----------|-------------|---------|
38| `prompt` | Text prompt (required) | `"Explain quantum computing"` |
39| `--model`, `-m` | Model to use | `gemini-3-flash-preview` |
40| `--system`, `-s` | System instruction | `"You are a helpful assistant"` |
41| `--thinking`, `-t` | Enable thinking mode | Flag |
42| `--json`, `-j` | Force JSON output | Flag |
43| `--grounding`, `-g` | Enable Google Search | Flag |
44| `--image`, `-i` | Image for multimodal | `photo.png` |
45| `--temperature` | Sampling 0.0-2.0 | `0.7` for creative |
46| `--max-tokens` | Output limit | `1000` |
47
48**Output**: Generated text string, optionally with grounding sources
49
50## Workflows
51
52### Workflow 1: Basic Text Generation
53```bash
54python scripts/generate.py "Explain quantum computing in simple terms"
55```
56- Best for: Simple content creation, explanations, summaries
57- Model: `gemini-3-flash-preview` (default, fast)
58
59### Workflow 2: With System Instruction (Persona)
60```bash
61python scripts/generate.py "How do I read a file in Python?" --system "You are a helpful coding assistant"
62```
63- Best for: Domain-specific tasks, expert personas, consistent tone
64- Use when: You need specific behavioral constraints
65
66### Workflow 3: Complex Reasoning (Thinking Mode)
67```bash
68python scripts/generate.py "Analyze the ethical implications of AI in healthcare" --thinking
69```
70- Best for: Complex analysis, step-by-step reasoning, multi-step problems
71- Use when: Task requires careful consideration and logical progression
72
73### Workflow 4: Structured JSON Output
74```bash
75python scripts/generate.py "Generate a user profile object with name, email, and preferences" --json
76```
77- Best for: Data extraction, structured data generation, API responses
78- Output: Valid JSON ready for parsing
79- Note: Prompt must clearly request JSON structure
80
81### Workflow 5: Real-Time Information (Grounding)
82```bash
83python scripts/generate.py "Who won the latest Super Bowl?" --grounding
84```
85- Best for: Current events, news, factual information after training cutoff
86- Output: Response + grounding sources with citations
87- Use when: Accuracy of current information is critical
88
89### Workflow 6: Multimodal (Image Analysis)
90```bash
91python scripts/generate.py "Describe what's in this image in detail" --image photo.png
92```
93- Best for: Image captioning, visual analysis, image-based Q&A
94- Requires: Image file in PNG or JPEG format
95- Combines well with: gemini-files for file upload
96
97### Workflow 7: Content Creation Pipeline (Batch + Text + TTS)
98```bash
99# 1. Create batch requests (gemini-batch skill)
100# 2. Generate content
101python scripts/generate.py "Create a 500-word blog post about sustainable energy"
102# 3. Convert to audio (gemini-tts skill)
103```
104- Best for: High-volume content production, podcasts, audiobooks
105
106## Parameters Reference
107
108### Model Selection
109
110| Model | Speed | Intelligence | Context | Best For |
111|-------|-------|--------------|---------|----------|
112| `gemini-3-flash-preview` | Fast | High | 1M | General use, agentic tasks (default) |
113| `gemini-3-pro-preview` | Medium | Highest | 1M | Complex reasoning, research |
114| `gemini-2.5-flash` | Fast | Medium | 1M | Stable, reliable generation |
115| `gemini-2.5-pro` | Slow | High | 1M | Code, math, STEM tasks |
116
117### Temperature Settings
118
119| Value | Creativity | Best For |
120|-------|-----------|----------|
121| 0.0-0.3 | Low | Code, facts, formal writing |
122| 0.4-0.7 | Medium | Balanced output |
123| 0.8-1.0 | High | Creative writing, brainstorming |
124| 1.0-2.0 | Very High | Highly creative, varied outputs |
125
126### Thinking Budget
127
128| Value | Description |
129|-------|-------------|
130| 0 | Disabled (default behavior) |
131| 512-1024 | Standard reasoning |
132| 2048+ | Deep analysis (slower, more tokens) |
133
134## Output Interpretation
135
136### Standard Text Output
137- Plain text response ready for use
138- Check for truncation if max-tokens was set
139- May include markdown formatting
140
141### JSON Output
142- Valid JSON object (use `--json` flag)
143- Parse with: `import json; data = json.loads(output)`
144- Verify structure matches your requirements
145- Handle potential parsing errors
146
147### Grounded Response
148When `--grounding` is used, the script prints:
1491. Main response text
1502. "--- Grounding Sources ---" section
1513. List of sources with titles and URLs
152
153### Thinking Mode Output
154- May include reasoning steps before final answer
155- Longer response times due to thinking process
156- Better for tasks requiring careful analysis
157
158## Common Issues
159
160### "google-genai not installed"
161```bash
162pip install google-genai
163```
164
165### "API key not set"
166Set environment variable:
167```bash
168export GOOGLE_API_KEY="your-key-here"
169# or
170export GEMINI_API_KEY="your-key-here"
171```
172
173### "Model not available"
174- Check model name spelling
175- Verify API access for selected model
176- Try `gemini-3-flash-preview` (most available)
177
178### JSON parse errors
179- Ensure prompt explicitly requests JSON structure
180- Check output for JSON formatting
181- Consider using system instruction: "You always respond with valid JSON"
182
183### Image file not found
184- Verify image path is correct
185- Use absolute paths if relative paths fail
186- Supported formats: PNG, JPEG
187
188### Response truncated
189- Increase `--max-tokens` value
190- Break task into smaller requests
191- Use pro models with higher token limits
192
193## Best Practices
194
195### Performance Optimization
196- Use flash models for speed, pro for quality
197- Lower temperature (0.0-0.3) for deterministic outputs
198- Set appropriate max-tokens to control costs
199- Use thinking mode only for complex tasks
200
201### Prompt Engineering
202- Be specific and clear in your prompts
203- Use system instructions for consistent behavior
204- Include examples in prompts for better results
205- For JSON: specify exact structure in prompt
206
207### Error Handling
208- Wrap script calls in try-except blocks
209- Validate JSON output before parsing
210- Handle network timeouts with retries
211- Check API quota limits for batch operations
212
213### Cost Management
214- Use flash models when possible (lower cost)
215- Limit max-tokens for simple queries
216- Cache results for repeated queries
217- Use batch API for high-volume tasks
218
219## Related Skills
220
221- **gemini-image**: Generate images from text
222- **gemini-tts**: Convert text to speech
223- **gemini-embeddings**: Create vector embeddings for semantic search
224- **gemini-files**: Upload files for multimodal processing
225- **gemini-batch**: Process multiple requests efficiently
226
227## Quick Reference
228
229```bash
230# Basic
231python scripts/generate.py "Your prompt"
232
233# Persona
234python scripts/generate.py "Prompt" --system "You are X"
235
236# Thinking
237python scripts/generate.py "Complex task" --thinking
238
239# JSON
240python scripts/generate.py "Generate JSON" --json
241
242# Search
243python scripts/generate.py "Current event" --grounding
244
245# Multimodal
246python scripts/generate.py "Describe this" --image photo.png
247```
248
249## Reference
250
251- See `references/models.md` for detailed model information
252- Get API key: https://aistudio.google.com/apikey
253- Documentation: https://ai.google.dev/gemini-api