How to create a chatBot connected to Azure OpenAI service — Javascript
Requirements
- Node.js
- Bot Framework Emulator
- Knowledge of restify and asynchronous programming in JavaScript
- Visual Studio Code or your favorite IDE, if you want to edit the bot code.
- Yeoman.io
npm install --global yo
- Botbuilder generator
npm install -g generator-botbuilder
Create an empty ECHO BOT
1- Open up your terminal and create a folder, then run: yo botbuilder
2- Open the project in vscode and make sure you are running the following versions and run npm install:
botbuilder ~4.17.0. / dotenv ~8.2.0 / replace ~1.2.0 / restify ~8.5.1
3- Run the project (npm start) to test echo bot.
Edit the bot.js to consume Azure Open AI Service
The API we will use will help us have a conversation with our bot. If you want to read more check out MS documentation. The key to use this service is to tell the API how it should behave and then provide a few examples. That’s why we will use the example provided by Microsoft:
Lets go ahead and create the url and heaver we will use to consume our service.
Next lets create the interfaces we will need to interact with and edit the message function.
Run and test your bot in the emulator. Congrats!
Code availble here: ivatilca/chatBotAzureOpenAI (github.com)