Files
StudyDiary/02-学习笔记/AI专题/免费使用Gemini 2.5 Pro的完整教程.md
2026-07-23 20:36:13 +08:00

140 lines
3.8 KiB
Markdown
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
created: 2025-08-30T11:45
updated: 2025-09-22T13:27
---
![](https://csdnimg.cn/release/blogv2/dist/pc/img/original.png)
[李孟聊人工智能](https://limeng.blog.csdn.net/ "李孟聊人工智能") ![](https://csdnimg.cn/release/blogv2/dist/pc/img/newUpTime2.png)
已于 2025-03-26 21:12:21 修改
于 2025-03-26 21:12:01 首次发布
本文为博主(李孟)原创文章,未经博主允许不得转载。
谷歌3月25日发布的Gemini 2.5 Pro可能成为AI发展史上的关键转折点。
尽管企业对其最新模型夸大其词已成常态,但2.5 Pro发布即登顶LMArena排行榜(该榜单由人类评估员根据交互质量和实用性对AI进行排名)的事实表明,这绝非营销噱头。
![](https://i-blog.csdnimg.cn/direct/08e3d6492aaf44898e7bc65ae76b9130.png)
该模型的独特之处在于其架构设计。
Gemini 2.5 Pro并非简单匹配训练数据模式,而是将谷歌所称的"思考能力"直接融入设计。
在生成回应前,模型会有意识地将复杂问题分解为逻辑步骤——这一过程比早期模型的统计近似更接近人类推理方式。
这并非思维链提示(chain-of-thought prompting)的简单重组,而是植根于模型底层的核心机制。
现在你可以在**Google Colab上免费使用**
**特点**
------
谷歌最新AI模型,拥有:
**100万token上下文窗口**(超长记忆!)
**推理能力超越GPT-4 Turbo**
**多模态支持**(文本/图像/代码/音频)
**比Gemini 1.5 Pro更快更便宜**
![](https://i-blog.csdnimg.cn/direct/6b46257540534aae9cd622935e3a53fa.png)
**性能基准**
--------
• MMLU测试准确率91.4%
• 复杂推理任务优于GPT-4
• 可处理超长文档(100万token≈70万单词!)
![](https://i-blog.csdnimg.cn/direct/6309afd04b484f889367b180ae5042be.png)
**Colab免费使用指南**
---------------
**步骤1:打开Google Colab**
👉 [点击此处进入Colab](https://colab.research.google.com/) [https://colab.research.google.com/](https://colab.research.google.com/)
**步骤2:安装并导入Gemini**
```python
!pip install google-genai
from google import genai
from google.genai import types
import os
from PIL import Image
```
**步骤3:设置API密钥(免费!)**
```python
os.environ["GEMINI_API_KEY"] = "您的API密钥"
gemini_client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
```
_注:_[在此获取API密钥](https://ai.google.dev/) [https://aistudio.google.com/](https://aistudio.google.com/)
**完整案例:多模态推理(文本+图像)**
---------------------
让Gemini根据路况图片判断卡车能否准时抵达目的地
📌 **代码实现**
```python
from google.colab import files
uploaded = files.upload()
image_path = next(iter(uploaded.keys()))
img = Image.open(image_path)
prompt = """
我正驾驶卡车行驶在这条路上,现在是中午12点。
能否在13点前到达110公里外的目的地?
"""
response = gemini_client.models.generate_content(
model="gemini-2.5-pro-exp-03-25",
contents=[prompt, img]
)
print(response.text)
```
**输入**
![](https://i-blog.csdnimg.cn/direct/f2bf58d674084403ac768ceb035d0b3a.png)
📸 **预期输出**
Gemini会分析道路图像(车流、限速等)并给出类似回答:
> “根据当前路况和卡车平均时速(60公里/小时),1小时内无法行驶110公里。至少需要1小时50分钟。”
**进阶技巧**
--------
• 使用高清图像提升分析精度
• 尝试超长上下文提示(上限100万token!)
• 组合文本+代码+图像进行复杂推理
**立即尝试并分享你的成果!** **你打算用Gemini 2.5 Pro开发什么?**
[Gemini 2.5 Pro 使用地址](https://aistudio.google.com/app/prompts/new_chat?model=gemini-2.5-pro-exp-03-25)