Skip to main content

Building an AI Chatbot with Llama 2 and nlux

In this section, we'll show you how to build an AI chatbot with Llama 2 (hosted on Hugging Face) and nlux.

How to connect to Llama 2 on Hugging Face

Installation

npm install @nlux/hf-react

Usage

import {
useChatAdapter,
llama2InputPreProcessor,
llama2OutputPreProcessor,
} from '@nlux/hf-react';

const Component = () => {
const adapter = useChatAdapter({
dataTransferMode: 'stream',
model: '<MODEL NAME OR URL>',
systemMessage: '<SYSTEM MESSAGE FOR LLAMA 2>',
preProcessors: {
input: llama2InputPreProcessor,
output: llama2OutputPreProcessor,
},
maxNewTokens: 800,
});

return (
<AiChat adapter={adapter} />
);
}