Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Babak committed Dec 15, 2023
1 parent 906c7df commit c03a168
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 134 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ migrate_working_dir/
.dart_tool/
.packages
build/
/test/env.dart
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## 0.0.1
## 0.0.1-dev-1

* TODO: Describe initial release.
* first publish
4 changes: 4 additions & 0 deletions lib/flutter_gemini.dart
Original file line number Diff line number Diff line change
@@ -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';
216 changes: 110 additions & 106 deletions lib/src/config/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,110 +8,114 @@ class Constants {
'https://generativelanguage.googleapis.com/v1beta/';

static List<GeminiModel> 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();
}
6 changes: 3 additions & 3 deletions lib/src/implement/gemini_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -22,7 +22,7 @@ class GeminiService {

Future<Response> post(
String route, {
required Map<String, Object>? data,
required Map<String, Object>? data,
GenerationConfig? generationConfig,
List<SafetySetting>? safetySettings,
}) async {
Expand Down
17 changes: 6 additions & 11 deletions lib/src/init.dart
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -41,13 +37,12 @@ class Gemini implements GeminiInterface {
GeminiImpl _impl;

/// singleton initialize
factory Gemini.init({
required String apiKey,
List<SafetySetting>? safetySettings,
GenerationConfig? generationConfig,
bool? enableDebugging
}) {
if(enableDebugging != null){
factory Gemini.init(
{required String apiKey,
List<SafetySetting>? safetySettings,
GenerationConfig? generationConfig,
bool? enableDebugging}) {
if (enableDebugging != null) {
Gemini.enableDebugging = enableDebugging;
}
if (_firstInit) {
Expand Down
3 changes: 0 additions & 3 deletions lib/src/repository/gemini_interface.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
12 changes: 9 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
12 changes: 7 additions & 5 deletions test/flutter_gemini_test.dart
Original file line number Diff line number Diff line change
@@ -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));
});
}

0 comments on commit c03a168

Please sign in to comment.