The repository simple_react_app is a minimal example of how to use OpenAssistant in a React project.
The basic structure is as follows:
src/
├── App.js
├── index.js
public/
├── index.html
├── package.json
To use OpenAssistant in your React project, you need to install the following packages:
yarn add @openassistant/ui @openassistant/core
import { Assistant } from '@openassistant/ui';
// for project not using tailwind, you need to import the css file
import '@openassistant/ui/dist/index.css';
function App() {
return (
<div style={{ width: '400px', height: '800px', margin: '20px' }}>
<Assistant
name="My Assistant"
apiKey=""
version="v1"
modelProvider="ollama"
model="llama3.1"
baseUrl="http://127.0.0.1:11434"
welcomeMessage="Hello, how can I help you today?"
instructions="You are a helpful assistant."
functions={[]}
/>
</div>
);
}
You can see the UI interface in browser if you run yarn start
.
![](https://private-user-images.githubusercontent.com/2423887/399046059-394a9bb6-6022-477d-a98d-f85db043ce71.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyODcyMTEsIm5iZiI6MTczOTI4NjkxMSwicGF0aCI6Ii8yNDIzODg3LzM5OTA0NjA1OS0zOTRhOWJiNi02MDIyLTQ3N2QtYTk4ZC1mODVkYjA0M2NlNzEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTFUMTUxNTExWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzVhYWE3YmU5YTZhOTIzN2NmNzhmYjU3NzhmY2FlZTNlYzZlMDQ3Y2E1MzFiOGY2OTYzZThlNzgxZTM3NWQ5NyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.AKhYhhuHenCnEqMK0V4PcxWJNk1FP4I2Rk5et1xj3Yo)
Download the Ollama desktop app from https://ollama.com/download and run it.
To run a model e.g. llama3.2, type in terminal:
ollama run llama3.2
If you want to download a model e.g. llama3.2, type in terminal:
ollama pull llama3.2
More information about ollama can be found in the ollama documentation.
Note:
If you need to access your local ollama from your published React app, you need to start the ollama server with the following command:
OLLAMA_ORIGINS=* ollama serve
yarn start
The UI component is using next-themes to support theme switching.
import { Assistant } from '@openassistant/ui';
// for project not using tailwind, you need to import the css file
import '@openassistant/ui/dist/index.css';
import { ThemeProvider } from 'next-themes';
function App() {
return (
<ThemeProvider attribute="class" forcedTheme="light">
<div style={{ width: '400px', height: '800px', margin: '20px' }}>
<AiAssistant
name="My Assistant"
apiKey=""
version="v1"
modelProvider="ollama"
model="llama3.1"
baseUrl="http://127.0.0.1:11434"
welcomeMessage="Hello, how can I help you today?"
instructions="You are a helpful assistant."
functions={[]}
/>
</div>
</ThemeProvider>
);
}