mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-05-14 05:40:16 +02:00
updating readme for widget (#2132)
Co-authored-by: Jos Van der westhuizen <jos@danser.ai>
This commit is contained in:
parent
3540aa579b
commit
0530f4283e
2
examples/widget/.env.example
Normal file
2
examples/widget/.env.example
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
NEXT_PUBLIC_API_URL=https://example.danswer.ai
|
||||||
|
NEXT_PUBLIC_API_KEY=some_long_api_key_here
|
@ -1,19 +1,70 @@
|
|||||||
This is a code example for how you can use Danswer's APIs to build a chat bot widget for a website! The main code to look at can be found in `src/app/widget/Widget.tsx`.
|
# Danswer Chat Bot Widget
|
||||||
|
Note: The widget requires a Danswer API key, which is a paid (cloud/enterprise) feature.
|
||||||
|
|
||||||
If you want to get fancier, then take a peek at the Chat implementation within Danswer itself [here](https://github.com/danswer-ai/danswer/blob/main/web/src/app/chat/ChatPage.tsx#L82).
|
This is a code example for how you can use Danswer's APIs to build a chat bot widget for a website! The main code to look at can be found in `src/app/widget/Widget.tsx`.
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
First, install the requirements:
|
To get the widget working on your webpage, follow these steps:
|
||||||
|
|
||||||
|
### 1. Install Dependencies
|
||||||
|
|
||||||
|
Ensure you have the necessary dependencies installed. From the `examples/widget/README.md` file:
|
||||||
```bash
|
```bash
|
||||||
npm i
|
npm i
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run the development server:
|
|
||||||
|
### 2. Set Environment Variables
|
||||||
|
|
||||||
|
Make sure to set the environment variables `NEXT_PUBLIC_API_URL` and `NEXT_PUBLIC_API_KEY` in a `.env` file at the root of your project:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
NEXT_PUBLIC_API_URL=
|
||||||
|
NEXT_PUBLIC_API_KEY=
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Run the Development Server
|
||||||
|
|
||||||
|
Start the development server to see the widget in action.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm run dev
|
npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||||
|
|
||||||
|
### 4. Integrate the Widget
|
||||||
|
|
||||||
|
To integrate the widget into your webpage, you can use the `ChatWidget` component. Here’s an example of how to include it in a page component:
|
||||||
|
|
||||||
|
```jsx
|
||||||
|
import ChatWidget from 'path/to/ChatWidget';
|
||||||
|
function MyPage() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>My Webpage</h1>
|
||||||
|
<ChatWidget />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
export default MyPage;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### 5. Deploy
|
||||||
|
|
||||||
|
Once you are satisfied with the widget, you can build and start the application for production:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run build
|
||||||
|
npm run start
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom Styling and Configuration
|
||||||
|
|
||||||
|
If you need to customize the widget, you can modify the `ChatWidget` component in the `examples/widget/src/app/widget/Widget.tsx` file.
|
||||||
|
|
||||||
|
By following these steps, you should be able to get the chat widget working on your webpage.
|
||||||
|
|
||||||
|
If you want to get fancier, then take a peek at the Chat implementation within Danswer itself [here](https://github.com/danswer-ai/danswer/blob/main/web/src/app/chat/ChatPage.tsx#L82).
|
Loading…
x
Reference in New Issue
Block a user