部署您的 Gemini AI

集成 Google 最强大的模型到您的本地工作流中。

macOS
Linux
Windows

01 安装 Gemini CLI 运行环境

我们将使用 Node.js 环境来驱动官方 CLI 工具。

npm install -g @google/gemini-cli

02 获取 API Key

前往 Google AI Studio

您需要一个 Google 账号来生成免费或付费等级的 API 密钥。

Get API Key

03 注入环境变量

为了安全起见,请将密钥配置在系统变量中。

echo 'export GEMINI_API_KEY="您的密钥"' >> ~/.zshrc
source ~/.zshrc

04 编写你的第一个脚本 (Node.js)

创建一个名为 app.js 的文件并粘贴以下代码。

import { GoogleGenerativeAI } from "@google/generative-ai";

const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

const prompt = "你好,Gemini!请简要自我介绍。";
const result = await model.generateContent(prompt);
console.log(result.response.text());

05 即刻启程

在终端执行以下命令,见证 Gemini 的力量。

node app.js