Closed faheem-riaz closed 3 months ago
@faheem-riaz, Can you try passing gemini-1.5-pro-latest
model in model parameter and use Gemini 1.5 pro instead of Gemini 1.0 pro model as System instructions are not supported in Gemini 1.0 pro models and should work with Gemini 1.5 pro models. Thank you!
@singhniraj08 Thanks it's working. can you tell me if i can use chat-bison instead of gemini models. i also want to ask what models are supported by this package as google have tons like vertex, palm chat bison and more
@faheem-riaz, models listed in Gemini models should work with GenerativeModel. I don't think chat-bison models supported by Vertex AI will work with Dart SDK. Thank you!
@singhniraj08 Thanks closing this.
Description of the bug:
I get this error when i set system instructions while creating my model.
_model = GenerativeModel( model: 'gemini-pro', apiKey: Env.geminiKey, systemInstruction: Content.text('You need to tell user poems'));
When i try to sendMessage I got this excpetion.Actual vs expected behavior:
Api should write poem for user.
Any other information you'd like to share?
Complete code `import 'dart:developer';
import 'package:ai_chat_characters/core/services/environment/env.dart'; import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:google_generative_ai/google_generative_ai.dart'; import 'package:stream_chat_flutter/stream_chat_flutter.dart';
@RoutePage() class ChatPage extends StatefulWidget { const ChatPage({super.key});
@override State createState() => _ChatPageState();
}
class _ChatPageState extends State {
late GenerativeModel _model;
late ChatSession _chatSession;
late Channel channel;
List messages = [];
@override void initState() { super.initState(); _model = GenerativeModel( model: 'gemini-pro', apiKey: Env.geminiKey, systemInstruction: Content.text('You need to tell user poems')); channel = StreamChat.of(context).client.channel( 'messaging', id: 'flutter_chat_ai_gen_1', )..watch().then((value) { // value.messages?.forEach((element) { // StreamChat.of(context).client.deleteMessage(element.id); // }); messages = value.messages ?? []; _startChat(); }); }
@override Widget build(BuildContext context) { return StreamChannel( channel: channel, child: _ChannelPage( onMessageSent: _generate, ), ); }
void _startChat() { _chatSession = _model.startChat(history: messages.map((e) => Content.text(e.text ?? '')).toList()); }
void _generate(Message message) async { var prompt = message.text!; if (prompt.isEmpty) return;
} }
/// Displays the list of messages inside the channel class _ChannelPage extends StatelessWidget { final ValueChanged onMessageSent;
const _ChannelPage({required this.onMessageSent});
@override Widget build(BuildContext context) { return Column( children:[
Expanded(
child: StreamMessageListView(
messageBuilder: (context, details, list, def) {
return def.copyWith(
reverse: !(details.message.extraData['isGeminiMessage'] as bool? ?? false),
borderRadiusGeometry: const BorderRadius.all(Radius.circular(16)),
showUsername: false,
showSendingIndicator: false,
showTimestamp: false,
);
},
),
),
StreamMessageInputTheme(
data: const StreamMessageInputThemeData(inputTextStyle: TextStyle()),
child: StreamMessageInput(
onMessageSent: onMessageSent,
showCommandsButton: false,
disableAttachments: true,
),
)
],
);
}
}
`