babakcode / flutter_gemini

Flutter Google Gemini SDK
https://pub.dev/packages/flutter_gemini
BSD 3-Clause "New" or "Revised" License
176 stars 53 forks source link

Gemini chat not work ERROR 400 #19

Closed hortigado closed 7 months ago

hortigado commented 7 months ago

Hi i implement GEMINI.CHAT but not work i get the error 400

  void fromText({required String query}) async {
    print(6666);
    loading = true;
    chats.add(Message(content: Content(role: 'user', parts: [Parts(text: query)])));
    update();
    textController.clear();
    scrollToTheEnd();
    try {
      List<Content> contents = [];
      for (var chat in chats) {
        contents.add(chat.content);
      }
      contents.add(Content(role: 'user', parts: [Parts(text: query)]));
      await gemini.chat(contents).then((value) {
        chats.add(Message(content: Content(role: 'model', parts: [Parts(text: value?.output)])));
      });
    } catch (e) {
      loading = false;
      chats.add(Message(content: Content(role: 'model', parts: [Parts(text: e.toString())])));
      update();
      scrollToTheEnd();
    }
  }

image

hortigado commented 7 months ago

My mistake i add two time contents.add(Content(role: 'user', parts: [Parts(text: query)]));