Can't seem to understand context

Hello. I am coding an assistant that should keep the user company. Problem is it doesn’t seem to understand my prompts, and it keeps repeating itself or answering in weird ways.

Context I provided the API:

List<Map<String, dynamic>> messages = [
    {
      'isUser': false,
      'message': 'The following is a conversation with Nety, an AI assistant. The assistant is helpful, creative, clever, and very friendly.',
      'isHidden': true,
    },
    {'isUser': false, 'message': 'I am Nety. Do you want me to keep you company?'}
  ];

API Code:

final url = 'https://api.openai.com/v1/chat/completions';

    List<Map<String, dynamic>> formattedMessages = messages.map((msg) {
      return {
        "role": msg['isUser'] ? "user" : "assistant",
        "content": msg['message'],
      };
    }).toList();

    final response = await http.post(
      Uri.parse(url),
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer $apiKey',
      },
      body: json.encode({
        'model': 'gpt-3.5-turbo',
        'messages': formattedMessages,
        'max_tokens': 150,
        'n': 1,
        'temperature': 0.9,
      }),
    );

Example of conversation, if we can call it that…

Cattura

I tried the same exact prompt in playground with

  • text-davinci-003
  • temperature 0.9
  • max length 150
    result:

The following is a conversation with Nety, an AI assistant. The assistant is helpful, creative, clever, and very friendly.

Nety: I am Nety. Do you want me to keep you company?
Human: yes
Nety: Great! I’m happy to be here for you. What can I do for you today?
Human:

What is your suggestion for this? Thank you in advance.

Welcome to the forum.

Are you sending the user messages back and appending them to the new prompt? That’s the only way to keep context…

Good luck.

1 Like

Hi Paul, I debugged my code and I noticed I was sending the list of messages from the last to the first, that was the cause of the weird behavior. Thanks! :smile:

1 Like

Hi Paul- Sorry to interject but you ‘replied ‘ to my post but just copied my post and I’m not able to reply. Can you please explain?