diff --git a/lib/providers/gemini_chat_provider.dart b/lib/providers/gemini_chat_provider.dart index e94066c..b442882 100644 --- a/lib/providers/gemini_chat_provider.dart +++ b/lib/providers/gemini_chat_provider.dart @@ -1,10 +1,8 @@ -import 'dart:developer'; - import 'package:flutter/material.dart'; +import 'package:flutter_gemini/flutter_gemini.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_chat_types/flutter_chat_types.dart' as types; import 'package:convogen/providers/app_settings_provider.dart'; -import 'package:google_gemini/google_gemini.dart'; var geminiChatProvider = StateNotifierProvider( @@ -19,6 +17,7 @@ class GeminiChatState { types.User(id: '1', firstName: 'Gemini', role: types.Role.user), types.User(id: '2', firstName: 'User', role: types.Role.user) ]; + const GeminiChatState( {required this.isLoading, required this.messages, @@ -82,14 +81,19 @@ class GeminiChatProvider extends StateNotifier { text: prompt, createdAt: DateTime.now().millisecondsSinceEpoch)); state = state.copyWith(isTyping: true); - var gemini = - GoogleGemini(apiKey: ref.read(appSettingsProvider).geminiApiKey); - var res = await gemini.generateFromText(prompt); - log(res.toString()); + + var chats = state.messages.map((dynamic e) => Content( + parts: [Parts(text: e.text)], + role: e.author == state.users[1] ? 'model' : 'user')); + var flutterGemini = + Gemini.init(apiKey: ref.read(appSettingsProvider).geminiApiKey); + + var res = await flutterGemini.chat(chats.toList().reversed.toList()); addMessage(types.TextMessage( author: state.users[1], id: DateTime.now().toString(), - text: res.text, + // text: res!.content!.parts!.map((e) => e.text).join("\n"), + text: res?.output ?? "Unable to proceed", createdAt: DateTime.now().millisecondsSinceEpoch)); state = state.copyWith(isTyping: false); } diff --git a/pubspec.lock b/pubspec.lock index c0b25e8..bf1e445 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -273,6 +273,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + dio: + dependency: transitive + description: + name: dio + sha256: "49af28382aefc53562459104f64d16b9dfd1e8ef68c862d5af436cc8356ce5a8" + url: "https://pub.dev" + source: hosted + version: "5.4.1" equatable: dependency: transitive description: @@ -342,6 +350,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" + flutter_gemini: + dependency: "direct main" + description: + name: flutter_gemini + sha256: "1e106f4644d1bc3b1806c9fbf0b6399873b16041d61ea12e3fc229f23f3aa067" + url: "https://pub.dev" + source: hosted + version: "2.0.3" flutter_link_previewer: dependency: transitive description: @@ -445,14 +461,6 @@ packages: url: "https://pub.dev" source: hosted version: "6.1.0" - google_gemini: - dependency: "direct main" - description: - name: google_gemini - sha256: "8cf19c909e5bfb0518391f4d538251f29e3283caa021249b76afcd69b2963e26" - url: "https://pub.dev" - source: hosted - version: "0.0.9" graphs: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9a1df37..a7bf318 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: convogen -description: "A new Flutter project." +description: "A AI Chatbot based on Google's Gemini." # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: "none" # Remove this line if you wish to publish to pub.dev @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+2 +version: 1.0.1 environment: sdk: ">=3.2.3 <4.0.0" @@ -37,7 +37,6 @@ dependencies: flutter_chat_ui: ^1.6.10 flutter_chat_types: ^3.6.2 provider: ^6.1.1 - google_gemini: ^0.0.9 flutter_riverpod: ^2.4.9 riverpod_annotation: ^2.3.3 shared_preferences: ^2.2.2 @@ -49,6 +48,7 @@ dependencies: google_fonts: ^6.1.0 flutter_svg: ^2.0.9 go_router: ^13.0.0 + flutter_gemini: ^2.0.3 dev_dependencies: flutter_test: