chrome_ai 包是 Chrome AI API 的 Flutter 包装,使开发者能够将其 Chrome AI 功能集成到 Flutter 应用中。它简化了对自然语言处理和生成式响应等 AI 功能的访问。该包专为在 Flutter 项目中无缝使用而设计,将复杂的 API 交互抽象为简单的方法。该包非常适合希望利用 AI 驱动的聊天、内容生成或智能用户辅助功能的应用。它支持未来的平台扩展,尽管当前的平台支持尚不明确。
适合场景
AI 驱动的聊天界面
应用中的内容生成
智能助手集成
实时语言处理
增强的用户与AI的互动
自动响应系统
主要特点
Chrome AI 的简单 API 包装器
无缝的 Flutter 集成
支持生成式AI任务
简洁、易于使用的方法
面向未来,支持平台扩展
轻量且专注
适合对象
开发 AI 增强型 Flutter 应用的开发者
集成Chrome AI功能的团队
需要实时文本生成的应用程序
原型设计人工智能驱动的用户体验
旨在最小化设置开销的项目
使用建议
未列出特定平台的支持
依赖外部 Chrome AI API 的可用性
有限的文档暗示
需要互联网连接以进行AI调用
取决于出版商的维护
不适用于离线AI功能
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
ChromeAI
Recently, Chrome has added window.ai — a Gemini Nano AI model right inside your browser. This means that web developers can instantly and unlimitedly use on-device AI without any configuration.
I believe this will truly transform web applications. The use-cases are endless: smart auto-completion, error correction and validation, natural language filtering, auto-filling forms, UI suggestions, first-pass summarization, and search.
Accordingly, I have developed a library to enable this feature in Flutter. With this library, you can easily utilize the feature in Flutter web as well.
Installation
you can watch this video to see how to enable AI in Chrome and run this library.
[chrome://components/](chrome://components/): Click Optimization Guide On Device Model to download the model.
2. Add library
flutter pub add chrome_ai
3. Run your project
1. Open terminal and run web-server
flutter run -d web-server
2. Open Chrome dev or canary, and open your project in http://localhost:port
Usage
Check Availability of Chrome AI
import'package:chrome_ai/chrome_ai.dart';
final availability = awaitChromeAI.canCreateTextSession();
if(availability == AIModelAvailability.no){
// can not create text session
}elseif(availability == AIModelAvailability.afterDownload) {
// need to download model
}elseif(availability == AIModelAvailability.readily){
// model is ready
}
Generate Text
import'package:chrome_ai/chrome_ai.dart';
final session = awaitChromeAI.createTextSession();
var result = await session.prompt("why is the sky blue?");
print(result);
Generate Streaming Text
import'package:chrome_ai/chrome_ai.dart';
final session = awaitChromeAI.createTextSession();
final stream = session.promptStreaming("why is the sky blue?");
stream.listen((result) {
print(result);
}).onError((e, stackTrace) {
print(e.toString());
});
Need Help!
This project is very new. If you have any questions, please open an issue. Contributions are very welcome.