Why ChatGPT cannot answer your Dialogflow question fully

Here is an example question I asked from StackOverflow:

And here is ChatGPT’s response:

It seems like you’re facing an issue with intent matching in Dialogflow where user queries intended for one intent (ALU_INFO) are being matched to another intent (CPU_INFO) due to the presence of the @components entity. This is a common challenge in chatbot development, but there are several strategies you can use to improve the intent matching and resolve this issue:

  1. Training Data: Make sure that your training data for each intent is comprehensive and specific. Include a variety of questions related to ALU and CPU in the ALU_INFO and CPU_INFO intents respectively. This will help Dialogflow learn the distinctions between the two intents better.
  2. Entity Synonyms: While it’s great to have synonyms for entities like “alu” and “cpu,” be cautious not to include synonyms that are too general and could lead to confusion. For example, if you have synonyms like “processing unit” for both ALU and CPU, it might contribute to the matching confusion.
  3. Contextual Entities: Use context to help the bot differentiate between the two intents. In this case, when the user asks about an ALU, you could set a context that indicates the conversation is about ALU-related information. This might guide Dialogflow to better match the user’s question to the correct intent.
  4. Intent Priority: You can assign higher priority to the ALU_INFO intent to ensure that when there’s ambiguity, Dialogflow gives preference to matching with that intent. Priority settings can influence intent matching when multiple intents are potentially applicable.
  5. Specific Training Phrases: Ensure that your training phrases for each intent are clear and specific. For the ALU_INFO intent, make sure you have training phrases that directly mention “alu” and related terms. Similarly, for CPU_INFO, focus on phrases related to CPUs.
  6. Testing and Iteration: Continuously test your bot with various user queries and evaluate the intent matching. If you notice any misclassifications, adjust your training data and entity usage accordingly. It might take some iteration to find the right balance.
  7. Contextual Understanding: Dialogflow’s ML-based system also considers the context of the conversation to determine the intent. Make sure that the response provided by the bot is also relevant to the user’s query. This can help Dialogflow understand whether the user is asking about ALU or CPU based on the context of the conversation.

By using these strategies, you should be able to improve the intent matching accuracy in your Dialogflow bot and ensure that user queries about ALU are correctly matched to the ALU_INFO intent rather than the CPU_INFO intent.

While there is nothing wrong with ChatGPT’s answer, it is not very helpful either.

You can provide this answer for almost any situation where Dialogflow matches the wrong intent.

Here is the correct answer:

You should combine the two intents into one, because otherwise it is too ambiguous for Dialogflow ES to distinguish between the two intents.

Once you combine them into a single intent, you can then use some webhook code to decide the next step.

Why did ChatGPT make this mistake?

So what happened? Why did ChatGPT make this mistake?

It is because there are 4 layers in a Dialogflow ES chatbot.

While ChatGPT can usually answer questions about the fulfillment layer and integration layer quite easily (as they are both code heavy), it will struggle with the conversation layer.

Fixing issues in the conversation layer requires the user to reason about the bot’s behavior, as we saw in the example above.

Sometimes ChatGPT provides wrong answers even for the fulfillment layer

I asked the following question to ChatGPT (all of this is on the latest version – GPT4)

How to generate suggestion chips rich response for Dialogflow Messenger from Python webhook

And this was ChatGPT’s response:

import json

def generate_response_with_suggestions(query_text, suggestions):
    response = {
        "fulfillmentMessages": [
            {
                "platform": "PLATFORM_UNSPECIFIED",
                "payload": {
                    "richContent": [
                        [
                            {
                                "type": "info",
                                "title": "Suggested Actions",
                                "suggestions": suggestions
                            }
                        ]
                    ]
                }
            }
        ]
    }

    return json.dumps(response)

# Example usage
query_text = "Welcome message"
suggestions = ["Option 1", "Option 2", "Option 3"]

response = generate_response_with_suggestions(query_text, suggestions)
print(response)

You can take a look at the Suggestion Chips rich response type in the documentation and see that ChatGPT’s response was wrong. In fact, even the “type” field is wrong, which means your webhook code will be sending the wrong type of rich response.

{
  "richContent": [
    [
      {
        "type": "chips",
        "options": [
          {
            "text": "Chip 1",
            "image": {
              "src": {
                "rawUrl": "https://example.com/images/logo.png"
              }
            },
            "link": "https://example.com"
          },
          {
            "text": "Chip 2",
            "image": {
              "src": {
                "rawUrl": "https://example.com/images/logo.png"
              }
            },
            "link": "https://example.com"
          }
        ]
      }
    ]
  ]
}

On top of that, the code has not been customized for a Python webhook, but instead is just generic code intended for any platform or channel.

In other words, even if you had to modify the code provided by ChatGPT, you needed to have some prior knowledge of how Dialogflow webhooks work.

Tips for writing code for your Dialogflow bot

I have actually been teaching Dialogflow for quite a while, and these ChatGPT responses are probably the perfect encapsulation of the problem with blindly copy-pasting code.

Once you master the basics (and do it systematically), it is actually very easy to write code for Dialogflow.

But you need to use what I call the explicative approach – learn to separate your bot into the four layers in such a way that you don’t mix them up unnecessarily. Let each layer do its job as it was designed.

(For example, don’t do slot filling using a webhook)