Skip to content

ChatBot

Albarqawi edited this page Jul 22, 2023 · 27 revisions

We will demonstrate how to use the IntelliNode library to create chatbots with various AI models, such as OpenAI chatGPT and Replicate (provider of Llama V2 model).

Let's get started. We'll first demonstrate how to set up a chatbot with OpenAI and then with Replicate's Llama V2 model.

ChatGPT Model

  1. Import the necessary modules from IntelliNode. This will include the Chatbot, ChatGPTInput, and ChatGPTMessage classes.
const { Chatbot, ChatGPTInput, ChatGPTMessage } = require('intellinode');
  1. To use OpenAI, you'll need a valid API key. Create a Chatbot instance, providing the OpenAI API key and 'openai' as the provider.
const chatbot = new Chatbot(OPENAI_API_KEY, 'openai');
  1. Construct a chat input instance and add user messages:
const system = 'You are a helpful assistant.';
const input = new ChatGPTInput(system);
input.addUserMessage('Explain the plot of the Inception movie in one line.');
  1. Use the chatbot instance to send chat input:
const responses = await chatbot.chat(input);

responses.forEach(response => console.log('- ', response));

LLama V2 Model

Now let's mov to the Llama V2 model from Replicate. The provided endpoint is still in the early stages and provides one input for each request.

  1. Import the necessary classes.
const { Chatbot, ChatLLamaInput, SupportedChatModels } = require('intellinode');
  1. You'll need a valid API key. This time, it should be for replicate.com.
const chatbot = new Chatbot(REPLICATE_API_KEY, SupportedChatModels.REPLICATE);
  1. Create the chat input with ChatLLamaInput
const system = 'You are a helpful assistant.';
const input = new ChatLLamaInput(system);
input.addUserMessage('Explain the plot of the Inception movie in one line.');
  1. Use the chatbot instance to send chat input:
const response = await chatbot.chat(input);

console.log('- ', response);
Clone this wiki locally