-
Notifications
You must be signed in to change notification settings - Fork 0
[Tutorial] Simple React App
Xun Li edited this page Dec 28, 2024
·
1 revision
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
.
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>
);
}