Preserve chat history of Assistants API using Flutter?

38 views Asked by At

This is the function that gets a message from Assistants API:

open_ai_service.dart

  final res = await _postRequest({
    "model": "gpt-4-turbo-preview",
    "max_tokens": 1000,
    "temperature": 0,
    "messages": [
      {
        "role": "user",
        "content": prompt,
      },
    ],
  });

Then, I use it in my chat_section.dart view, and try to store messages locally via

  List<Map<String, dynamic>> chatHistory = [
    {'text': 'Hi, how can I help you?', 'isUser': false}
  ]; //

As you can see I even pre-filled it with a default message from AI side, and it works.

However, each time I open the page, new chat (or thread) gets created.

I think we need something like this: https://platform.openai.com/docs/api-reference/threads

However I struggle to have a full picture in mind. If there is no a single answer, I would appreciate the direction on where to find one!

Happy to provide additional details, thanks!

0

There are 0 answers