genkit-dart

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Genkit Dart

Genkit Dart

Genkit Dart is an AI SDK for Dart that provides a unified interface for code generation, structured outputs, tools, flows, and AI agents.
Genkit Dart是一款面向Dart的AI SDK,为代码生成、结构化输出、工具、流程(Flows)以及AI Agent提供统一接口。

Core Features and Usage

核心功能与使用

If you need help with initializing Genkit (
Genkit()
), Generation (
ai.generate
), Tooling (
ai.defineTool
), Flows (
ai.defineFlow
), Embeddings (
ai.embedMany
), streaming, or calling remote flow endpoints, please load the core framework reference: references/genkit.md
如果您需要了解Genkit初始化(
Genkit()
)、生成功能(
ai.generate
)、工具定义(
ai.defineTool
)、流程定义(
ai.defineFlow
)、嵌入功能(
ai.embedMany
)、流式传输或调用远程流程端点等相关内容,请查阅核心框架参考文档: references/genkit.md

Genkit CLI (recommended)

Genkit CLI(推荐使用)

The Genkit CLI provides a local development UI for running Flow, tracing executions, playing with models, and evaluating outputs.
check if the user has it installed:
genkit --version
Installation:
bash
curl -sL cli.genkit.dev | bash # Native CLI
Genkit CLI为本地开发提供了可视化界面,可用于运行Flow、追踪执行过程、测试模型以及评估输出结果。
检查是否已安装:
genkit --version
安装方式:
bash
curl -sL cli.genkit.dev | bash # 原生CLI

OR

或者

npm install -g genkit-cli # Via npm

**Usage:**
Wrap your run command with `genkit start` to attach the Genkit developer UI and tracing:
```bash
genkit start -- dart run main.dart
npm install -g genkit-cli # 通过npm安装

**使用方法:**
在运行命令前加上`genkit start`,即可启用Genkit开发者UI与追踪功能:
```bash
genkit start -- dart run main.dart

Plugin Ecosystem

插件生态系统

Genkit relies on a large suite of plugins to perform generative AI actions, interface with external LLMs, or host web servers.
When asked to use any given plugin, always verify usage by referring to its corresponding reference below. You should load the reference when you need to know the specific initialization arguments, tools, models, and usage patterns for the plugin:
Plugin NameReference LinkDescription
genkit_google_genai
references/genkit_google_genai.mdLoad for Google Gemini plugin interface usage.
genkit_anthropic
references/genkit_anthropic.mdLoad for Anthropic plugin interface for Claude models.
genkit_openai
references/genkit_openai.mdLoad for OpenAI plugin interface for GPT models, Groq, and custom compatible endpoints.
genkit_middleware
references/genkit_middleware.mdLoad for Tooling for specific agentic behavior:
filesystem
,
skills
, and
toolApproval
interrupts.
genkit_mcp
references/genkit_mcp.mdLoad for Model Context Protocol integration (Server, Host, and Client capabilities).
genkit_chrome
references/genkit_chrome.mdLoad for Running Gemini Nano locally inside the Chrome browser using the Prompt API.
genkit_shelf
references/genkit_shelf.mdLoad for Integrating Genkit Flow actions over HTTP using Dart Shelf.
genkit_firebase_ai
references/genkit_firebase_ai.mdLoad for Firebase AI plugin interface (Gemini API via Vertex AI).
Genkit依赖丰富的插件集来执行生成式AI操作、对接外部大语言模型(LLM)或托管Web服务器。
当需要使用任意插件时,请务必参考下方对应的参考文档来确认使用方法。当您需要了解插件的具体初始化参数、工具、模型及使用模式时,请查阅对应的参考文档:
插件名称参考链接描述
genkit_google_genai
references/genkit_google_genai.md用于Google Gemini插件对接。
genkit_anthropic
references/genkit_anthropic.md用于对接Anthropic的Claude模型插件。
genkit_openai
references/genkit_openai.md用于对接OpenAI的GPT模型、Groq及自定义兼容端点的插件。
genkit_middleware
references/genkit_middleware.md用于实现特定Agent行为的工具插件:包括
filesystem
skills
toolApproval
中断处理。
genkit_mcp
references/genkit_mcp.md用于集成模型上下文协议(Model Context Protocol),支持服务器、主机及客户端功能。
genkit_chrome
references/genkit_chrome.md用于在Chrome浏览器内通过Prompt API本地运行Gemini Nano。
genkit_shelf
references/genkit_shelf.md用于通过Dart Shelf将Genkit Flow操作集成到HTTP服务中。
genkit_firebase_ai
references/genkit_firebase_ai.md用于Firebase AI插件对接(通过Vertex AI访问Gemini API)。

External Dependencies

外部依赖

Whenever you define schemas mapping inside of Tools, Flows, and Prompts, you must use the schemantic library. To learn how to use schemantic, ensure you read the
schemantic
skill for how to implement type safe generated Dart code. This is particularly relevant when you encounter symbols like
@Schematic()
,
stringSchema()
,
intSchema()
,
mapSchema()
, or classes with the
$
prefix. Genkit Dart uses schemantic for all of its data models so it's a CRITICAL skill to understand for using Genkit Dart.
当您在工具、流程及提示词中定义模式映射时,必须使用schemantic库。 要了解如何使用schemantic,请务必阅读
schemantic
相关指南,学习如何实现类型安全的Dart生成代码。当您遇到
@Schematic()
stringSchema()
intSchema()
mapSchema()
或带有
$
前缀的类时,这一点尤为重要。Genkit Dart的所有数据模型均基于schemantic构建,因此掌握它是使用Genkit Dart的必备技能。

Best Practices

最佳实践

  • Always check that code cleanly compiles using
    dart analyze
    before generating the final response.
  • Always use the Genkit CLI for local development and debugging.
  • 在生成最终响应前,务必使用
    dart analyze
    检查代码是否能正常编译。
  • 本地开发与调试时,请始终使用Genkit CLI。