# Gemini (/zh/developer-guides/llm-sdks-and-frameworks/gemini)

<!-- agent-signals: reading_time_min: 2 · est_tokens: 841 · updated: 2026-07-30 -->
Related: [OpenAI](/zh/developer-guides/llm-sdks-and-frameworks/openai.md), [Anthropic](/zh/developer-guides/llm-sdks-and-frameworks/anthropic.md), [Agent Development Kit（ADK）](/zh/developer-guides/llm-sdks-and-frameworks/google-adk.md), [Vercel AI SDK](/zh/developer-guides/llm-sdks-and-frameworks/vercel-ai-sdk.md), [LangChain](/zh/developer-guides/llm-sdks-and-frameworks/langchain.md), [LangGraph](/zh/developer-guides/llm-sdks-and-frameworks/langgraph.md)

将 Firecrawl 与 Google 的 Gemini 集成，以构建由网页数据驱动的 AI 应用。

<div id="setup">
  ## 安装与配置 [#安装与配置]
</div>

```bash
npm install firecrawl @google/genai
```

创建“.env”文件：

```bash
FIRECRAWL_API_KEY=your_firecrawl_key
GEMINI_API_KEY=your_gemini_key
```

> **注意：** 如果使用 Node 版本低于 20，请安装 `dotenv`，并在代码中添加 `import 'dotenv/config'`。

<div id="scrape-summarize">
  ## 抓取 + 摘要 [#抓取--摘要]
</div>

此示例演示了一个简单的工作流：抓取网站并使用 Gemini 对内容生成摘要。

```typescript
import { Firecrawl } from 'firecrawl';
import { GoogleGenAI } from '@google/genai';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

const scrapeResult = await firecrawl.scrape('https://firecrawl.dev', {
    formats: ['markdown']
});

console.log('Scraped content length:', scrapeResult.markdown?.length);

const response = await ai.models.generateContent({
    model: 'gemini-2.5-flash',
    contents: `Summarize: ${scrapeResult.markdown}`,
});

console.log('Summary:', response.text);
```

<div id="content-analysis">
  ## 内容分析 [#内容分析]
</div>

此示例展示了如何使用 Gemini 的多轮对话功能来分析网页内容。

```typescript
import { Firecrawl } from 'firecrawl';
import { GoogleGenAI } from '@google/genai';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

const scrapeResult = await firecrawl.scrape('https://news.ycombinator.com/', {
    formats: ['markdown']
});

console.log('Scraped content length:', scrapeResult.markdown?.length);

const chat = ai.chats.create({
    model: 'gemini-2.5-flash'
});

// 获取 Hacker News 上的前 3 条热门内容
const result1 = await chat.sendMessage({
    message: `Based on this website content from Hacker News, what are the top 3 stories right now?\n\n${scrapeResult.markdown}`
});
console.log('Top 3 Stories:', result1.text);

// 获取 Hacker News 上的第 4 和第 5 条热门内容
const result2 = await chat.sendMessage({
    message: `Now, what are the 4th and 5th top stories on Hacker News from the same content?`
});
console.log('4th and 5th Stories:', result2.text);
```

<div id="structured-extraction">
  ## 结构化数据提取 [#结构化数据提取]
</div>

此示例演示了如何使用 Gemini 的 JSON 模式，从已抓取的网站内容中提取结构化数据。

```typescript
import { Firecrawl } from 'firecrawl';
import { GoogleGenAI, Type } from '@google/genai';

const firecrawl = new Firecrawl({ apiKey: process.env.FIRECRAWL_API_KEY });
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

const scrapeResult = await firecrawl.scrape('https://stripe.com', {
    formats: ['markdown']
});

console.log('抓取的内容长度:', scrapeResult.markdown?.length);

const response = await ai.models.generateContent({
    model: 'gemini-2.5-flash',
    contents: `提取公司信息: ${scrapeResult.markdown}`,
    config: {
        responseMimeType: 'application/json',
        responseSchema: {
            type: Type.OBJECT,
            properties: {
                name: { type: Type.STRING },
                industry: { type: Type.STRING },
                description: { type: Type.STRING },
                products: {
                    type: Type.ARRAY,
                    items: { type: Type.STRING }
                }
            },
            propertyOrdering: ['name', 'industry', 'description', 'products']
        }
    }
});

console.log('已提取的公司信息:', response?.text);
```

更多示例请参阅 [Gemini 文档](https://ai.google.dev/docs)。
