From c03a168724b90407dfeebcdf2d80348e83d86d38 Mon Sep 17 00:00:00 2001 From: Babak Date: Fri, 15 Dec 2023 15:35:38 +0330 Subject: [PATCH] some changes --- .gitignore | 1 - CHANGELOG.md | 4 +- lib/flutter_gemini.dart | 4 + lib/src/config/constants.dart | 216 ++++++++++++----------- lib/src/implement/gemini_service.dart | 6 +- lib/src/init.dart | 17 +- lib/src/repository/gemini_interface.dart | 3 - pubspec.yaml | 12 +- test/flutter_gemini_test.dart | 12 +- 9 files changed, 141 insertions(+), 134 deletions(-) diff --git a/.gitignore b/.gitignore index 438ccb8..96486fd 100644 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,3 @@ migrate_working_dir/ .dart_tool/ .packages build/ -/test/env.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 41cc7d8..bd49d37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,3 @@ -## 0.0.1 +## 0.0.1-dev-1 -* TODO: Describe initial release. +* first publish diff --git a/lib/flutter_gemini.dart b/lib/flutter_gemini.dart index e8344d8..9c61cac 100644 --- a/lib/flutter_gemini.dart +++ b/lib/flutter_gemini.dart @@ -1,3 +1,7 @@ library flutter_gemini; export 'src/init.dart'; +export 'src/models/gemini_response/gemini_response.dart'; +export 'src/models/gemini_safety/gemini_safety.dart'; +export 'src/models/gemini_safety/gemini_safety_category.dart'; +export 'src/models/gemini_safety/gemini_safety_threshold.dart'; diff --git a/lib/src/config/constants.dart b/lib/src/config/constants.dart index d0284fc..4e56022 100644 --- a/lib/src/config/constants.dart +++ b/lib/src/config/constants.dart @@ -8,110 +8,114 @@ class Constants { 'https://generativelanguage.googleapis.com/v1beta/'; static List get geminiDefaultModels => [ - { - "name": "models/chat-bison-001", - "version": "001", - "displayName": "Chat Bison", - "description": "Chat-optimized generative language model.", - "inputTokenLimit": 4096, - "outputTokenLimit": 1024, - "supportedGenerationMethods": ["generateMessage", "countMessageTokens"], - "temperature": 0.25, - "topP": 0.95, - "topK": 40 - }, - { - "name": "models/text-bison-001", - "version": "001", - "displayName": "Text Bison", - "description": "Model targeted for text generation.", - "inputTokenLimit": 8196, - "outputTokenLimit": 1024, - "supportedGenerationMethods": [ - "generateText", - "countTextTokens", - "createTunedTextModel" - ], - "temperature": 0.7, - "topP": 0.95, - "topK": 40 - }, - { - "name": "models/embedding-gecko-001", - "version": "001", - "displayName": "Embedding Gecko", - "description": "Obtain a distributed representation of a text.", - "inputTokenLimit": 1024, - "outputTokenLimit": 1, - "supportedGenerationMethods": ["embedText", "countTextTokens"] - }, - { - "name": "models/embedding-gecko-002", - "version": "002", - "displayName": "Embedding Gecko 002", - "description": "Obtain a distributed representation of a text.", - "inputTokenLimit": 2048, - "outputTokenLimit": 1, - "supportedGenerationMethods": ["embedText", "countTextTokens"] - }, - { - "name": "models/gemini-pro", - "version": "001", - "displayName": "Gemini Pro", - "description": "The best model for scaling across a wide range of tasks", - "inputTokenLimit": 30720, - "outputTokenLimit": 2048, - "supportedGenerationMethods": ["generateContent", "countTokens"], - "temperature": 0.9, - "topP": 1, - "topK": 1 - }, - { - "name": "models/gemini-pro-vision", - "version": "001", - "displayName": "Gemini Pro Vision", - "description": - "The best image understanding model to handle a broad range of applications", - "inputTokenLimit": 12288, - "outputTokenLimit": 4096, - "supportedGenerationMethods": ["generateContent", "countTokens"], - "temperature": 0.4, - "topP": 1, - "topK": 32 - }, - { - "name": "models/gemini-ultra", - "version": "001", - "displayName": "Gemini Ultra", - "description": "The most capable model for highly complex tasks", - "inputTokenLimit": 30720, - "outputTokenLimit": 2048, - "supportedGenerationMethods": ["generateContent", "countTokens"], - "temperature": 0.9, - "topP": 1, - "topK": 32 - }, - { - "name": "models/embedding-001", - "version": "001", - "displayName": "Embedding 001", - "description": "Obtain a distributed representation of a text.", - "inputTokenLimit": 2048, - "outputTokenLimit": 1, - "supportedGenerationMethods": ["embedContent", "countTextTokens"] - }, - { - "name": "models/aqa", - "version": "001", - "displayName": "Model that performs Attributed Question Answering.", - "description": - "Model trained to return answers to questions that are grounded in provided sources, along with estimating answerable probability.", - "inputTokenLimit": 7168, - "outputTokenLimit": 1024, - "supportedGenerationMethods": ["generateAnswer"], - "temperature": 0.2, - "topP": 1, - "topK": 40 - } - ].map((e) => GeminiModel.fromJson(e)).toList(); + { + "name": "models/chat-bison-001", + "version": "001", + "displayName": "Chat Bison", + "description": "Chat-optimized generative language model.", + "inputTokenLimit": 4096, + "outputTokenLimit": 1024, + "supportedGenerationMethods": [ + "generateMessage", + "countMessageTokens" + ], + "temperature": 0.25, + "topP": 0.95, + "topK": 40 + }, + { + "name": "models/text-bison-001", + "version": "001", + "displayName": "Text Bison", + "description": "Model targeted for text generation.", + "inputTokenLimit": 8196, + "outputTokenLimit": 1024, + "supportedGenerationMethods": [ + "generateText", + "countTextTokens", + "createTunedTextModel" + ], + "temperature": 0.7, + "topP": 0.95, + "topK": 40 + }, + { + "name": "models/embedding-gecko-001", + "version": "001", + "displayName": "Embedding Gecko", + "description": "Obtain a distributed representation of a text.", + "inputTokenLimit": 1024, + "outputTokenLimit": 1, + "supportedGenerationMethods": ["embedText", "countTextTokens"] + }, + { + "name": "models/embedding-gecko-002", + "version": "002", + "displayName": "Embedding Gecko 002", + "description": "Obtain a distributed representation of a text.", + "inputTokenLimit": 2048, + "outputTokenLimit": 1, + "supportedGenerationMethods": ["embedText", "countTextTokens"] + }, + { + "name": "models/gemini-pro", + "version": "001", + "displayName": "Gemini Pro", + "description": + "The best model for scaling across a wide range of tasks", + "inputTokenLimit": 30720, + "outputTokenLimit": 2048, + "supportedGenerationMethods": ["generateContent", "countTokens"], + "temperature": 0.9, + "topP": 1, + "topK": 1 + }, + { + "name": "models/gemini-pro-vision", + "version": "001", + "displayName": "Gemini Pro Vision", + "description": + "The best image understanding model to handle a broad range of applications", + "inputTokenLimit": 12288, + "outputTokenLimit": 4096, + "supportedGenerationMethods": ["generateContent", "countTokens"], + "temperature": 0.4, + "topP": 1, + "topK": 32 + }, + { + "name": "models/gemini-ultra", + "version": "001", + "displayName": "Gemini Ultra", + "description": "The most capable model for highly complex tasks", + "inputTokenLimit": 30720, + "outputTokenLimit": 2048, + "supportedGenerationMethods": ["generateContent", "countTokens"], + "temperature": 0.9, + "topP": 1, + "topK": 32 + }, + { + "name": "models/embedding-001", + "version": "001", + "displayName": "Embedding 001", + "description": "Obtain a distributed representation of a text.", + "inputTokenLimit": 2048, + "outputTokenLimit": 1, + "supportedGenerationMethods": ["embedContent", "countTextTokens"] + }, + { + "name": "models/aqa", + "version": "001", + "displayName": "Model that performs Attributed Question Answering.", + "description": + "Model trained to return answers to questions that are grounded in provided sources, along with estimating answerable probability.", + "inputTokenLimit": 7168, + "outputTokenLimit": 1024, + "supportedGenerationMethods": ["generateAnswer"], + "temperature": 0.2, + "topP": 1, + "topK": 40 + } + ].map((e) => GeminiModel.fromJson(e)).toList(); } diff --git a/lib/src/implement/gemini_service.dart b/lib/src/implement/gemini_service.dart index 343cae2..5a652dd 100644 --- a/lib/src/implement/gemini_service.dart +++ b/lib/src/implement/gemini_service.dart @@ -10,8 +10,8 @@ class GeminiService { final Dio dio; final String apiKey; - GeminiService(this.dio, {required this.apiKey}){ - if(!kReleaseMode && Gemini.enableDebugging){ + GeminiService(this.dio, {required this.apiKey}) { + if (!kReleaseMode && Gemini.enableDebugging) { dio.interceptors .add(LogInterceptor(requestBody: true, responseBody: true)); } @@ -22,7 +22,7 @@ class GeminiService { Future post( String route, { - required Map? data, + required Map? data, GenerationConfig? generationConfig, List? safetySettings, }) async { diff --git a/lib/src/init.dart b/lib/src/init.dart index 0336d45..b2cb901 100644 --- a/lib/src/init.dart +++ b/lib/src/init.dart @@ -1,21 +1,17 @@ import 'dart:async'; import 'dart:typed_data'; import 'package:flutter_gemini/src/models/candidates/candidates.dart'; - import 'config/constants.dart'; import 'implement/gemini_service.dart'; import 'models/embedding/embedding_input_type.dart'; import 'models/gemini_model/gemini_model.dart'; -import 'models/gemini_response/gemini_response.dart'; import 'models/generation_config/generation_config.dart'; import 'repository/gemini_interface.dart'; import 'package:dio/dio.dart'; - import 'implement/gemini_implement.dart'; import 'models/gemini_safety/gemini_safety.dart'; class Gemini implements GeminiInterface { - /// to see request progress static bool enableDebugging = false; @@ -41,13 +37,12 @@ class Gemini implements GeminiInterface { GeminiImpl _impl; /// singleton initialize - factory Gemini.init({ - required String apiKey, - List? safetySettings, - GenerationConfig? generationConfig, - bool? enableDebugging - }) { - if(enableDebugging != null){ + factory Gemini.init( + {required String apiKey, + List? safetySettings, + GenerationConfig? generationConfig, + bool? enableDebugging}) { + if (enableDebugging != null) { Gemini.enableDebugging = enableDebugging; } if (_firstInit) { diff --git a/lib/src/repository/gemini_interface.dart b/lib/src/repository/gemini_interface.dart index 081ae9a..0fa1386 100644 --- a/lib/src/repository/gemini_interface.dart +++ b/lib/src/repository/gemini_interface.dart @@ -1,11 +1,8 @@ import 'dart:async'; import 'dart:typed_data'; - import 'package:flutter_gemini/src/models/candidates/candidates.dart'; - import '../models/embedding/embedding_input_type.dart'; import '../models/gemini_model/gemini_model.dart'; -import '../models/gemini_response/gemini_response.dart'; import '../models/gemini_safety/gemini_safety.dart'; import '../models/generation_config/generation_config.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index d0cead1..5d4fac4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,13 @@ name: flutter_gemini -description: Flutter Google Gemini SDK -version: 0.0.1 -homepage: +description: Flutter Google Gemini SDK. Google Gemini is a set of cutting-edge large language models + (LLMs) designed to be the driving force behind Google's future AI initiatives. +version: 0.0.1-dev-1 +homepage: https://github.com/babakcode/flutter_gemini +topics: + - gemini + - ai + - google-gemini + - flutter-gemini environment: sdk: '>=3.1.3 <4.0.0' diff --git a/test/flutter_gemini_test.dart b/test/flutter_gemini_test.dart index 8c4955b..fe7db80 100644 --- a/test/flutter_gemini_test.dart +++ b/test/flutter_gemini_test.dart @@ -1,15 +1,17 @@ +import 'dart:developer'; + import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_gemini/flutter_gemini.dart'; -import 'env.dart' as env; void main() { - Gemini.init(apiKey: env.geminiKey, enableDebugging: true); + Gemini.init(apiKey: '--- Your Gemini Api Key ---', enableDebugging: true); test('check gemini to generate simple text', () async { final gemini = Gemini.instance; - gemini.textInput("Write a story about a magic backpack.") - .then((value) => value?.content?.parts?.last.text) - .catchError((e) => print(e)); + gemini + .textInput("Write a story about a magic backpack.") + .then((value) => log(value?.content?.parts?.last.text ?? '')) + .catchError((e) => log('text input exception', error: e)); }); }