QAPlugin Adding custom AI

Jul 17, 2019 at 3:58 PM
QAPlugin Adding custom AI
  • QAPlugin
    Adding custom AI using DialogFlow

    QAPlugin gives you the ability to use DialogFlow to create your own AI. Some quick information about DialogFlow: It is a framework used in Google Home, Slack and other bots/assistants.

    Unlike the standard "question"->"response" AI you can make in the plugin by default, this framework allows you to create more dynamic conversations and even allows you to contact web services to answer the questions.

    It has the ability to learn variations on a question or to remember contextual questions. The best example to explain context is with a simple "Who is the president of the US? " question. Context allows you to ask follow up questions such as "How tall is he?", referring to the answer of the previous question.

    Use V1 for agents

    1. Log in to the site http://www.api.ai/
    2. Create a new agent. You can use "customer service" as the example application
      [​IMG]
    3. Test something basic.
      [​IMG]
      The framework has something called "domains" what are basically pre defined AI components such as (in this case ) small talk.
    4. You can enable new domains giving you the ability to add more functionalities
      [​IMG]
    5. Keep in mind, you can test the domains, but most of them require a plan upgradehelp
    6. You can experiment and play around on the site. Once you are ready you can add this AI bot to your minecraft server!
    7. Click on the gear icon next to your agent
      [​IMG]
    8. Copy the CLIENT access token
      [​IMG]
    9. In the config.yml paste the access token under "question-settings.api-ai.client-access-token"
    10. Do not forget to enable api-ai as well

    Learn from your players
    You can use the API to learn from your players
    [​IMG]
    API.ai will store all the questions and the frequency they are asked so you can add responses to them.

    Using user context
    Every time a player asks a question there will be a "context" created called "player"
    This context has several parameters you can use:

    • #player.username
    • #player.uuid
    • #player.location_x
    • #player.location_y
    • #player.location_z
    • #player.location_world

    [​IMG]
    Read more: https://docs.api.ai/docs/concept-contexts


    Read more at: https://docs.api.ai/docs/reference
    A php example can be found here: https://discuss.api.ai/t/webhook-in-php-example/229


    NOTE EVERYTHING BELOW THIS LINE IS FOR QAPlugin 4.0.0


    Configuration(top)

    Step 1 - Create a Google App(top)

    DialogFlow uses Google Cloud's API's. By default, you can make 180 requests per minute, what should suffice for most servers. However, if you have a larger server - you can use Google Cloud's API's to pay per additional requests (optional).

    The first thing you should do is go to:
    https://console.developers.google.com/
    Tip: It is advised to login with a regular Gmail account. If you have a Gsuite account (school account, company account,...) you require permission to create Google Applications.

    Step 2 - Add DialogFlow API to your project(top)

    After the creation of the Google project, you will see a screen saying "No API's have been added yet"
    [​IMG]
    Click the "+ Enable API's and services" button and search for "DialogFlow"
    On this page, you can see the pricing - however as mentioned in Step 1, you are not required to pay and can have a reasonable amount of requests per minute.
    [​IMG]
    Enable the api by clicking "Enable".

    Step 3 - Create credentials(top)

    After enabling the API, you need to create credentials. These credentials will be used by the QAPlugin to contact Google through your project.

    Normally, a message should show that you are required to create credentials:
    [​IMG]
    However, if this does not show: Simply go to "Credentials" on the left panel.
    Create a new "Service account key"
    [​IMG]
    You will be asked to selected the API (DialogFlow) and format. Select JSON and click 'Create'
    [​IMG]
    A JSON file will be automatically downloaded. Keep this file safe! You will need it in a later step.

    Step 4 - Create a DialogFlow agent(top)

    Each AI or trained personality in DialogFlow is called an "Agent". This step will create a new DialogFlow agent.
    Go to: https://console.dialogflow.com and log in with the same account as the one you created the Google application with.

    Click the button "Create agent" on the top left
    [​IMG]

    Give your agent a name, default language and timezone.
    Lastly, make sure to link the agent to the Google Project application you created in Step 1
    [​IMG]

    Step 5 - QAPlugin config.yml configuration(top)

    The next step is to let QAPlugin know about your agent. You will need two things:
    • The xxx.json file you have downloaded before in step 3
    • The

    DialogFlow configuration(top)

    Configuring DialogFlow is already widely documented on https://dialogflow.com/docs with videos and examples.

    You can even use "prebuild" agents that do basic things such as detecting weather related questions or customer support questions.
    [​IMG]

    This tutorial section will discuss the pure basics of DialogFlow and will delve deeper into the link with QAPlugin and your Minecraft server.

    Tutorial 1 - Understand intents, entities and dialog control(top)

    DialogFlow contains two important things: Intents and Entities.
    Intents are the different types of questions you can ask your AI.Each intent consist of several "training phrases", that represent the different ways you can ask the question.
    Example would be: "How old are you?" , "what is your age? ". DialogFlow can learn from these phrases to detect variants or other phrases mean the same thing. So its not like you would have to create every combination in the world.

    Next are entities. Entities are things you need to extract from your question. By default, there are already entities for cities, countries, locations, numbers, ... but you can add and train other types of entities.

    Tutorial 2 - Creating a basic intent(top)


    Tutorial 3 - Understanding contexts and events(top)

    Contexts are additional (hidden) data that is transmitted and included in a question. By default, QAPlugin provides each question with a player object that has basic information about the player:
    • #player.username
    • #player.uuid
    • #player.location_x
    • #player.location_y
    • #player.location_z
    • #player.location_world
  • Loading...
  • Loading...