Search code examples
node.jswit.ai

Changing Wit.ai Default Max Steps


For some reason I'm unable to increase the default max steps for my chat bot.

It seems that this number is now defined in lib/config.js rather than lib/wit.js like it used to be. No matter what I change the DEFAULT_MAX_STEPS constant to in my config file my bot seems to hit the same limit (5) before throwing the 'Max steps reached, stopping' error in my log when I want the bot to send a few responses/execute a few actions in a row.

I've tried linking the file the same way the example project seems to link to the wit.js and log.js files in the module via node-wit/lib

The config file:

enter image description here

How I've tried to link it to my index.js file:

enter image description here

I'm assuming I'm not referencing the config.js file properly...


Solution

  • I'll write example steps of using node-wit

    1) create and app folder, go to it and run: npm init

    2) run npm i --save node-wit

    3) app.js :

    const {Wit, log, config} = require('node-wit');
    const client = new Wit({accessToken: 'MY_TOKEN'});
    

    4) from documentation:

    runActions

    A higher-level method to the Wit converse API. runActions resets the last turn on new messages and errors.

    Takes the following parameters:

    sessionId - a unique identifier describing the user session
    message - the text received from the user
    context - the object representing the session state
    maxSteps - (optional) the maximum number of actions to execute (defaults to 5)
    

    so I'll add MAX_STEPS to example there:

    const MAX_STEPS = 25;
    const sessionId = 'some-session-id';
    const context0 = {};
    client
      .runActions(sessionId, 'events nearby', context0, MAX_STEPS)
      .then((context1) => {
        return client.runActions(sessionId, 'how about in London?', context1, MAX_STEPS - 1);
      })
      .then((context2) => {
        console.log('The session state is now: ' + JSON.stringify(context2));
      })
      .catch((e) => {
        console.log('Oops! Got an error: ' + e);
      });