视频
https://www.bilibili.com/video/BV1gH4y177sy/
前言
原文 https://ducafecat.com/blog/flutter-gemini-ai-integration
本文通过 Flutter 插件 google_generative_ai 快速的集成了 google ai gemini 来实现一个水贴的工具。
代码
https://github.com/ducafecat/flutter_develop_tips/tree/main/flutter_application_gemini
gemini 介绍
门户站
https://gemini.google.com/
开发站
https://ai.google.dev/
Google Cloud 收费
https://console.cloud.google.com
参考
https://medium.com/flutter/harness-the-gemini-api-in-your-dart-and-flutter-apps-00573e560381
https://ai.google.dev/tutorials/dart_quickstart?hl=zh-cn
https://ai.google.dev/models/gemini?hl=zh-cn
技术限制
限制国家 IP
限制模拟器运行,需要真机运行
准备工作
获取 gemini api key
https://aistudio.google.com/app/apikey?hl=zh-cn
Flutter 开发步骤
添加 pub 包
pubspec.yaml
dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 google_generative_ai: ^0.2.1 dio: ^5.4.1 flutter_markdown: ^0.6.20
插件包站:
https://flutter.ducafecat.com
https://pub.dev
准备图片
pubspec.yaml
# The following section is specific to Flutter packages.flutter: # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: true # To add assets to your application, add an assets section, like this: assets: - assets/images/
准备了 1.jpg 2.jpg , 一会让 gemini 识别下图片内容。
配置 API Key
.vscode/launch.json
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
“version”: “0.2.0”,
“configurations”: [
{
“name”: “flutter_application_gemini”,
“request”: “launch”,
“type”: “dart”,
“flutterMode”: “debug”,
“program”: “lib/main.dart”,
“args”: [“–dart-define=API_KEY=you key”]
},
{
“name”: “flutter_application_gemini (profile mode)”,
“request”: “launch”,
“type”: “dart”,
“flutterMode”: “profile”
},
{
“name”: “flutter_application_gemini (release mode)”,
“request”: “launch”,
“type”: “dart”,
“flutterMode”: “release”
首页
lib/index.dart
标题
内容生成
lib/content.dart
标题、发送、复制
暂无评论内容