-
Notifications
You must be signed in to change notification settings - Fork 17
ChatBot
Albarqawi edited this page Jul 24, 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, andChatGPTMessageclasses.
const { Chatbot, ChatGPTInput, ChatGPTMessage } = require('intellinode');- To use OpenAI, you'll need a valid API key. Create a
Chatbotinstance, 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
chatbotinstance 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, LLamaReplicateInput, 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
LLamaReplicateInput
const system = 'You are a helpful assistant.';
const input = new LLamaReplicateInput(system);
input.addUserMessage('Explain the plot of the Inception movie in one line.');- Use the
chatbotinstance to send chat input:
const response = await chatbot.chat(input);
console.log('- ', response);