gemini-text
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGemini Text Generation
Gemini文本生成
Generate content using Google's Gemini API through executable scripts with advanced capabilities including system instructions, thinking mode, JSON output, and Google Search grounding.
通过可执行脚本使用Google的Gemini API生成内容,具备系统指令、思维模式、JSON输出和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)
当你需要以下功能时使用本技能:
- 生成任意类型的文本内容(博客、邮件、代码、故事)
- 结合文本描述或分析处理图片
- 执行需要逐步思考的复杂推理
- 获取用于数据处理的结构化JSON输出
- 通过Google Search获取实时信息
- 应用特定角色或行为模式
- 将文本生成与其他Gemini技能(图片、TTS、嵌入)结合使用
Available Scripts
可用脚本
scripts/generate.py
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 |
|---|---|---|
| Text prompt (required) | |
| Model to use | |
| System instruction | |
| Enable thinking mode | Flag |
| Force JSON output | Flag |
| Enable Google Search | Flag |
| Image for multimodal | |
| Sampling 0.0-2.0 | |
| Output limit | |
Output: Generated text string, optionally with grounding sources
用途:具备所有Gemini功能的全特性文本生成工具
适用场景:
- 任意文本生成任务
- 多模态提示词(文本+图片)
- 需要思维模式的复杂推理
- 结构化JSON输出需求
- 实时信息获取需求(grounding)
- 自定义系统指令/角色
关键参数:
| 参数 | 描述 | 示例 |
|---|---|---|
| 文本提示词(必填) | |
| 使用的模型 | |
| 系统指令 | |
| 启用思维模式 | 标志位 |
| 强制输出JSON | 标志位 |
| 启用Google Search | 标志位 |
| 用于多模态的图片 | |
| 采样温度(0.0-2.0) | |
| 输出长度限制 | |
输出:生成的文本字符串,可附带grounding来源
Workflows
工作流
Workflow 1: Basic Text Generation
工作流1:基础文本生成
bash
python scripts/generate.py "Explain quantum computing in simple terms"- Best for: Simple content creation, explanations, summaries
- Model: (default, fast)
gemini-3-flash-preview
bash
python scripts/generate.py "Explain quantum computing in simple terms"- 最佳适用:简单内容创作、解释、摘要
- 默认模型:(速度快)
gemini-3-flash-preview
Workflow 2: With System Instruction (Persona)
工作流2:带系统指令(角色设定)
bash
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
bash
python scripts/generate.py "How do I read a file in Python?" --system "You are a helpful coding assistant"- 最佳适用:特定领域任务、专家角色、一致语气
- 适用场景:需要特定行为约束时
Workflow 3: Complex Reasoning (Thinking Mode)
工作流3:复杂推理(思维模式)
bash
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
bash
python scripts/generate.py "Analyze the ethical implications of AI in healthcare" --thinking- 最佳适用:复杂分析、逐步推理、多步骤问题
- 适用场景:任务需要细致考量和逻辑递进时
Workflow 4: Structured JSON Output
工作流4:结构化JSON输出
bash
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
bash
python scripts/generate.py "Generate a user profile object with name, email, and preferences" --json- 最佳适用:数据提取、结构化数据生成、API响应
- 输出:可直接解析的有效JSON
- 注意:提示词必须明确要求JSON结构
Workflow 5: Real-Time Information (Grounding)
工作流5:实时信息获取(Grounding)
bash
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
bash
python scripts/generate.py "Who won the latest Super Bowl?" --grounding- 最佳适用:当前事件、新闻、训练 cutoff 后的事实信息
- 输出:响应内容 + 带引用的grounding来源
- 适用场景:当前信息的准确性至关重要时
Workflow 6: Multimodal (Image Analysis)
工作流6:多模态(图片分析)
bash
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
bash
python scripts/generate.py "Describe what's in this image in detail" --image photo.png- 最佳适用:图片标题生成、视觉分析、基于图片的问答
- 要求:PNG或JPEG格式的图片文件
- 最佳搭配:gemini-files技能用于文件上传
Workflow 7: Content Creation Pipeline (Batch + Text + TTS)
工作流7:内容创作流水线(批量+文本+TTS)
bash
undefinedbash
undefined1. Create batch requests (gemini-batch skill)
1. 创建批量请求(gemini-batch技能)
2. Generate content
2. 生成内容
python scripts/generate.py "Create a 500-word blog post about sustainable energy"
python scripts/generate.py "Create a 500-word blog post about sustainable energy"
3. Convert to audio (gemini-tts skill)
3. 转换为音频(gemini-tts技能)
- Best for: High-volume content production, podcasts, audiobooks- 最佳适用:高容量内容生产、播客、有声书Parameters Reference
参数参考
Model Selection
模型选择
| Model | Speed | Intelligence | Context | Best For |
|---|---|---|---|---|
| Fast | High | 1M | General use, agentic tasks (default) |
| Medium | Highest | 1M | Complex reasoning, research |
| Fast | Medium | 1M | Stable, reliable generation |
| Slow | High | 1M | Code, math, STEM tasks |
| 模型 | 速度 | 智能程度 | 上下文长度 | 最佳适用场景 |
|---|---|---|---|---|
| 快 | 高 | 1M | 通用场景、智能体任务(默认) |
| 中等 | 最高 | 1M | 复杂推理、研究 |
| 快 | 中等 | 1M | 稳定、可靠的生成 |
| 慢 | 高 | 1M | 代码、数学、STEM任务 |
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 |
| 数值 | 创意程度 | 最佳适用场景 |
|---|---|---|
| 0.0-0.3 | 低 | 代码、事实、正式写作 |
| 0.4-0.7 | 中等 | 平衡型输出 |
| 0.8-1.0 | 高 | 创意写作、头脑风暴 |
| 1.0-2.0 | 极高 | 高度创意、多样化输出 |
Thinking Budget
思维预算
| Value | Description |
|---|---|
| 0 | Disabled (default behavior) |
| 512-1024 | Standard reasoning |
| 2048+ | Deep analysis (slower, more tokens) |
| 数值 | 描述 |
|---|---|
| 0 | 禁用(默认行为) |
| 512-1024 | 标准推理 |
| 2048+ | 深度分析(速度慢、消耗更多tokens) |
Output Interpretation
输出解读
Standard Text Output
标准文本输出
- Plain text response ready for use
- Check for truncation if max-tokens was set
- May include markdown formatting
- 可直接使用的纯文本响应
- 如果设置了max-tokens,检查是否被截断
- 可能包含Markdown格式
JSON Output
JSON输出
- Valid JSON object (use flag)
--json - Parse with:
import json; data = json.loads(output) - Verify structure matches your requirements
- Handle potential parsing errors
- 有效的JSON对象(使用标志位)
--json - 解析方式:
import json; data = json.loads(output) - 验证输出结构是否符合需求
- 处理潜在的解析错误
Grounded Response
Grounded响应
When is used, the script prints:
--grounding- Main response text
- "--- Grounding Sources ---" section
- List of sources with titles and URLs
当使用时,脚本会输出:
--grounding- 主要响应文本
- "--- Grounding Sources ---" 部分
- 包含标题和URL的来源列表
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"
"google-genai not installed"
bash
pip install google-genaibash
pip install google-genai"API key not set"
"API key not set"
Set environment variable:
bash
export GOOGLE_API_KEY="your-key-here"设置环境变量:
bash
export GOOGLE_API_KEY="your-key-here"or
or
export GEMINI_API_KEY="your-key-here"
undefinedexport GEMINI_API_KEY="your-key-here"
undefined"Model not available"
"Model not available"
- Check model name spelling
- Verify API access for selected model
- Try (most available)
gemini-3-flash-preview
- 检查模型名称拼写
- 验证所选模型的API访问权限
- 尝试使用(可用性最高)
gemini-3-flash-preview
JSON parse errors
JSON解析错误
- Ensure prompt explicitly requests JSON structure
- Check output for JSON formatting
- Consider using system instruction: "You always respond with valid JSON"
- 确保提示词明确要求JSON结构
- 检查输出的JSON格式
- 考虑使用系统指令:"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
- 验证图片路径是否正确
- 如果相对路径失败,使用绝对路径
- 支持的格式:PNG、JPEG
Response truncated
响应被截断
- Increase value
--max-tokens - Break task into smaller requests
- Use pro models with higher token limits
- 提高的值
--max-tokens - 将任务拆分为更小的请求
- 使用支持更高token限制的pro模型
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
- 追求速度用flash模型,追求质量用pro模型
- 降低温度(0.0-0.3)以获得确定性输出
- 设置合适的max-tokens以控制成本
- 仅在复杂任务中使用思维模式
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
- 提示词要具体清晰
- 使用系统指令确保行为一致
- 提示词中包含示例以获得更好的结果
- 生成JSON时:在提示词中指定确切的结构
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
- 将脚本调用包裹在try-except块中
- 解析前验证JSON输出
- 处理网络超时,实现重试机制
- 批量操作时检查API配额限制
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
- 尽可能使用flash模型(成本更低)
- 简单查询限制max-tokens
- 缓存重复查询的结果
- 高容量任务使用批量API
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
- gemini-image:从文本生成图片
- gemini-tts:将文本转换为语音
- gemini-embeddings:创建用于语义搜索的向量嵌入
- gemini-files:上传文件用于多模态处理
- gemini-batch:高效处理多个请求
Quick Reference
快速参考
bash
undefinedbash
undefinedBasic
Basic
python scripts/generate.py "Your prompt"
python scripts/generate.py "Your prompt"
Persona
Persona
python scripts/generate.py "Prompt" --system "You are X"
python scripts/generate.py "Prompt" --system "You are X"
Thinking
Thinking
python scripts/generate.py "Complex task" --thinking
python scripts/generate.py "Complex task" --thinking
JSON
JSON
python scripts/generate.py "Generate JSON" --json
python scripts/generate.py "Generate JSON" --json
Search
Search
python scripts/generate.py "Current event" --grounding
python scripts/generate.py "Current event" --grounding
Multimodal
Multimodal
python scripts/generate.py "Describe this" --image photo.png
undefinedpython scripts/generate.py "Describe this" --image photo.png
undefinedReference
参考资料
- See for detailed model information
references/models.md - Get API key: https://aistudio.google.com/apikey
- Documentation: https://ai.google.dev/gemini-api
- 查看获取详细模型信息
references/models.md - 获取API密钥:https://aistudio.google.com/apikey
- 文档:https://ai.google.dev/gemini-api