chrome_ai パッケージは、Chrome AI API の Flutter ラッパーであり、開発者が Flutter アプリケーションに Chrome AI 機能を統合できるようにします。自然言語処理や生成応答などのAI機能へのアクセスを簡素化しています。Flutter プロジェクトでのスムーズな使用を目的として設計されており、複雑なAPI操作を簡単なメソッドに抽象化しています。AI駆動のチャット、コンテンツ生成、または知的なユーザー支援を活用したいアプリに最適です。将来のプラットフォーム拡張をサポートしていますが、現在のプラットフォーム対応は未指定です。
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.