dcycle / starterkit-node

0 stars 1 forks source link

Have a text-based conversational framework with different plugins #44

Closed alberto56 closed 1 month ago

alberto56 commented 1 month ago

Download the latest branch of https://github.com/dcycle/starterkit-node

./scripts/deploy.sh

We want to have a text-based conversational framework with different plugins.

The first plugin will be a simple calculator.

Therefore there should be two (2) extensions added:

We would like to be able to do the following:

await app.c('chatbot')
  .chat({
    plugin: 'calculator',
    text: '2+2',
  });

This should return:

{
  result: 4,
  conversationId: '47388896-c8fd-400f-b123-0a9e16ea171f',
}

Then we can do

await app.c('chatbot')
  .chat({
    conversationId: '47388896-c8fd-400f-b123-0a9e16ea171f',
    text: '+5',
  });

This should return:

{
  result: 9,
  conversationId: '47388896-c8fd-400f-b123-0a9e16ea171f',
}

If we do

await app.c('chatbot')
  .chat({
    plugin: 'this-plugin-does-not-exist',
    text: '2+2',
  });

This should return:

{
  errors: [
    'Plugin this-plugin-does-not-exist does not exist',
  ],
}

If we do

await app.c('chatbot')
  .chat({
    text: '2+2',
  });

This should return:

{
  errors: [
    'Specify either a plugin or a conversationId',
  ],
}

Most of the work will be done by ./app/code/chatbot, and ./app/code/chatbotCalculator/index.js will look something like:

class ChatbotCalculator extends require('../component/index.js') {
  async conversation(prompt, previous)  {
    /**
     * previous will be something like:
     * [] (if this is a new chat)
     * or
     * [
     *   {
     *     prompt: '2+2',
     *     result: '4',
     *   },
     * ]
     */
     If (!previous) {
        // this is a new chat
        return this.getResult(prompt);
     }
     else {
        // this is a continuation of a chat
        return this.getResult(previous[0].result + prompt);
     }
  }
  dependencies() {
    return [
      './chatbot/index.js',
    ];
  }
}

Your task

In addition to making ChatbotCalculator, you will need to create Chatbot as well, which will be responsible for storing conversations in the database and directing them to the correct plugin.

Eventually we can add more plugins, such as a weather plugin, a translation plugin, an AI plugin, etc.

alberto56 commented 1 month ago

Closing with https://github.com/dcycle/starterkit-node/pull/45