-
Notifications
You must be signed in to change notification settings - Fork 16
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.
- Import the necessary modules from IntelliNode. This will include the
Chatbot
,ChatGPTInput
, andChatGPTMessage
classes.
const { Chatbot, ChatGPTInput, ChatGPTMessage } = require('intellinode');
- 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');
- 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.');
- Use the
chatbot
instance to send chat input:
const responses = await chatbot.chat(input);
responses.forEach(response => console.log('- ', response));
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.
- Import the necessary classes.
const { Chatbot, ChatLLamaInput, SupportedChatModels } = require('intellinode');
- You'll need a valid API key. This time, it should be for replicate.com.
const chatbot = new Chatbot(REPLICATE_API_KEY, SupportedChatModels.REPLICATE);
- 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.');
- Use the
chatbot
instance to send chat input:
const response = await chatbot.chat(input);
console.log('Chatbot response (replicate):', response);