@flink-app/gemini-adapter

中文文档
2.0.0-alpha.134发布于 2026/11/07MITTypeScriptCommonJS近 30 天下载 4904

Google Gemini adapter for Flink AI framework

原始使用文档
文档目录10 节
  1. Installation
  2. Usage
  3. Configuration
  4. Supported Models
  5. Thinking
  6. Structured Output and Tool Choice
  7. Image Model
  8. Features
  9. Using with FlinkAgent
  10. License

@flink-app/gemini-adapter

Google Gemini adapter for the Flink AI framework, built on the @google/genai SDK (the Gemini Developer API). The SDK is a regular dependency, nothing else needs installing.

Installation

npm install @flink-app/gemini-adapter

Usage

import { GeminiAdapter } from "@flink-app/gemini-adapter";
import { FlinkApp } from "@flink-app/flink";

const app = new FlinkApp({
  ai: {
    llms: {
      default: new GeminiAdapter({
        apiKey: process.env.GOOGLE_AI_API_KEY!,
        model: "gemini-2.0-flash",
      }),
    },
  },
});

Configuration

OptionTypeRequiredDescription
apiKeystringYesGoogle AI API key
modelstringYesGemini model name (e.g. "gemini-2.0-flash", "gemini-1.5-pro")
thinkingConfigGeminiThinkingConfigNoPassed through as config.thinkingConfig (includeThoughts, thinkingBudget, thinkingLevel, any future field)
debugbooleanNoEnable debug logging (default: false)

Supported Models

  • gemini-2.0-flash — Fast, cost-effective (recommended default)
  • gemini-1.5-pro — High capability, longer context
  • gemini-1.5-flash — Fast, balanced capability
  • gemini-2.5-pro-preview-03-25 — Latest preview model

Thinking

Thinking models (Gemini 2.5 / 3 series) are configured with thinkingConfig, passed through verbatim as config.thinkingConfig:

const adapter = new GeminiAdapter({
  apiKey: process.env.GOOGLE_AI_API_KEY!,
  model: "gemini-2.5-pro",
  thinkingConfig: { includeThoughts: true, thinkingBudget: 2048 }, // optional
});
  • With includeThoughts: true, thought summaries are streamed as reasoning chunks and surfaced by the agent as reasoning_delta events on fullStream. They never appear in textStream or result.message. Summaries are not sent back to Gemini.
  • Thought signatures returned on text and function call parts are captured (providerData.gemini.signatures) and replayed on the same parts in later turns. Gemini 3 rejects tool-call continuations with a 400 when the first function call's signature is missing, so this happens regardless of thinkingConfig.
  • Thinking tokens (thoughtsTokenCount) are included in the reported outputTokens.

Structured Output and Tool Choice

An agent's model.structuredOutput is sent as config.responseMimeType: "application/json" plus responseSchema. Gemini takes an OpenAPI-style subset of JSON Schema, so $schema, $ref, $defs, additionalProperties and default are stripped (the same sanitization tool schemas get). The parsed reply is available as result.structured.

Gemini does not accept a response schema together with function declarations. On steps that carry tools the schema is requested through the system instruction instead, and Flink validates the reply; the native response schema is used as soon as a step has no tools.

model.toolChoice is sent as toolConfig.functionCallingConfig: "auto" → AUTO, "none" → NONE, "required" → ANY, { type: "tool", name } → ANY with allowedFunctionNames: [name]. Only sent when the request carries tools.

Image Model

GeminiImageModel implements Flink's ImageModel interface for the image-capable Gemini models (gemini-3.1-flash-image, gemini-3-pro-image, gemini-3.1-flash-lite-image) through generateContent with image response modality.

import { GeminiImageModel } from "@flink-app/gemini-adapter";

const app = new FlinkApp<AppCtx>({
    ai: {
        images: {
            default: new GeminiImageModel({ apiKey: process.env.GEMINI_API_KEY!, model: "gemini-3.1-flash-image", imageSize: "2K" }),
        },
    },
});

const { images } = await ctx.ai.images.default.edit({
    prompt: "Make it night time, keep the car unchanged",
    images: [imageFromBuffer(file, "image/png")],
});
  • Editing is prompt driven: Gemini takes no mask (capabilities.mask is false, a mask fails with unsupported)
  • size is reduced to an aspect ratio with a warning; n above one is served by parallel requests
  • Text returned alongside the image lands in providerMetadata.gemini.text; providerOptions.gemini is merged into the request config
  • See the Image Models guide

Features

  • ✅ Tool calling support
  • ✅ Thinking (thinkingConfig passthrough), thought summaries as reasoning_delta, thought signatures replayed across turns
  • ✅ Streaming responses (SSE / NDJSON)
  • ✅ Alternating turn enforcement (consecutive same-role messages are merged)
  • ✅ System instruction handling
  • ✅ JSON Schema sanitization for Gemini compatibility
  • ✅ Token usage tracking
  • ✅ Debug logging

Using with FlinkAgent

import { FlinkAgent } from "@flink-app/flink";
import { GeminiAdapter } from "@flink-app/gemini-adapter";

export default class CarAgent extends FlinkAgent<AppContext> {
  instructions = "You are a helpful car assistant.";
  llm = new GeminiAdapter({
    apiKey: process.env.GOOGLE_AI_API_KEY!,
    model: "gemini-2.0-flash",
  });
}

License

MIT

版本与发布记录

@flink-app/gemini-adapter 共发布 67 个版本,首次发布于 2026/03/09;过去 12 个月发布了 67 个版本。

版本发布日期距今
2.0.0-alpha.134latest2026/11/078 天前
2.0.0-alpha.1332026/11/069 天前
2.0.0-alpha.1322026/11/0510 天前
2.0.0-alpha.1312026/10/2818 天前
2.0.0-alpha.1302026/10/2521 天前
2.0.0-alpha.1292026/10/2521 天前

关于 @flink-app/gemini-adapter 的常见问题

@flink-app/gemini-adapter 是什么?

Google Gemini adapter for Flink AI framework

如何安装 @flink-app/gemini-adapter?

在项目目录运行 npm install @flink-app/gemini-adapter,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@flink-app/flink(>=2.0.0-alpha.134)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flink-app/gemini-adapter 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flink-app/gemini-adapter 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@flink-app/gemini-adapter 可以商用吗?

@flink-app/gemini-adapter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flink-app/gemini-adapter 的下载量有多少?

根据 npm 官方下载统计,@flink-app/gemini-adapter 在 2026/10/15 – 2026/11/13 这 30 天内被下载 4,904 次,日均约 163 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flink-app/gemini-adapter 还在维护吗?

最新版本 2.0.0-alpha.134 发布于 2026/11/07(8 天前);至今共发布 67 个版本,其中过去 12 个月发布了 67 个;首次发布于 2026/03/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。