0

I'm creating a chat bot using wit.ai python API. I'm hoping to use converse in that. In there examples it only exists node examples for converse. Is there anyone who can help me with a example of wit.ai converse using python.

below is the node example they have.

//Extract an entity value from the entities returned by Wit
const firstEntityValue = (entities, entity) => {
  const val = entities && entities[entity] &&
    Array.isArray(entities[entity]) &&
    entities[entity].length > 0 &&
    entities[entity][0].value
  ;
  if (!val) {
    return null;
  }
  return typeof val === 'object' ? val.value : val;
};

//Define your bot functions here
const actions = {
  send(request, response) {
    const {sessionId, context, entities} = request;
    const {text, quickreplies} = response;
    return new Promise(function(resolve, reject) {
        console.log('user said...', request.text);
        console.log('sending...', JSON.stringify(response));
        return resolve();
    });
  },
  ['compute-result']({context,entities}) {
    return new Promise(function(resolve, reject) {
      const movie_title = firstEntityValue(entities, 'movie');
      if (movie_title) {
        context.movie = movie_title;
      }
      //call the API here
      return resolve(context);
  });
 },
};
jayz
  • 401
  • 1
  • 5
  • 25

1 Answers1

3

You can check the python examples of Wit at https://github.com/wit-ai/pywit/blob/master/examples The file joke.py would be enough to know the basic working in python.

Vrushab Maitri
  • 330
  • 3
  • 14