From 3247c617820640b336aa1b231d14c69fb5c68e13 Mon Sep 17 00:00:00 2001 From: Vinay Rawat Date: Sun, 21 Apr 2024 12:12:16 +0530 Subject: [PATCH] fixed image calling --- lib/providers/gemini_chat_provider.dart | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/providers/gemini_chat_provider.dart b/lib/providers/gemini_chat_provider.dart index 90f8bb9..b8c29d2 100644 --- a/lib/providers/gemini_chat_provider.dart +++ b/lib/providers/gemini_chat_provider.dart @@ -79,7 +79,7 @@ class GeminiChatProvider extends StateNotifier { getPrompt(String prompt, XFile? result) async { var model = GenerativeModel( - model: 'gemini-pro', + model: result == null ? 'gemini-pro' : 'gemini-pro-vision', apiKey: ref.read(appSettingsProvider).geminiApiKey); var filteredMessage = state.messages.whereType(); // return; @@ -118,12 +118,14 @@ class GeminiChatProvider extends StateNotifier { try { if (prompt.isEmpty && result == null) return; if (result != null) {} - var res = await chat.sendMessage(result == null - ? Content.text(prompt) - : Content.multi([ - TextPart(prompt), - ...[DataPart("image/jpeg", await result.readAsBytes())] - ])); + var res = result == null + ? await chat.sendMessage(Content.text(prompt)) + : await model.generateContent([ + Content.multi([ + TextPart(prompt), + ...[DataPart("image/jpeg", await result.readAsBytes())] + ]) + ]); log(res.text!); addMessage(types.TextMessage( author: state.users[1],