# @dopt/ai-assistant-react

> A React SDK accessing AI functionality

Latest version **0.1.1** (published 2024-04-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @dopt/ai-assistant-react
pnpm add @dopt/ai-assistant-react
yarn add @dopt/ai-assistant-react
bun add @dopt/ai-assistant-react
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2024-04-24 |
| First published | 2024-02-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 42.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | kseth, alexchantastic, pankaj-avhad-dopt, chasebish, joemckenney |

## Links

- npm: https://www.npmjs.com/package/@dopt/ai-assistant-react
- Repository: https://github.com/dopt/odopt
- Homepage: https://github.com/dopt/odopt/tree/main/packages/%40dopt/ai-assistant/react
- Issues: https://github.com/dopt/odopt/issues
- npm.io page: https://npm.io/package/@dopt/ai-assistant-react

## Dependencies (5)

- [@dopt/logger](https://npm.io/package/@dopt/logger.md) 0.2.0
- [react-hotkeys-hook](https://npm.io/package/react-hotkeys-hook.md) 4.4.0
- [@dopt/ai-assistant-context](https://npm.io/package/@dopt/ai-assistant-context.md) 0.0.10
- [@dopt/ai-assistant-definition](https://npm.io/package/@dopt/ai-assistant-definition.md) 0.0.8
- [@dopt/ai-assistant-javascript](https://npm.io/package/@dopt/ai-assistant-javascript.md) 0.0.16

## Recent versions

- 0.1.1 (latest) — 2024-04-24
- 0.1.0 — 2024-04-22
- 0.0.15 — 2024-04-18
- 0.0.13 — 2024-03-06
- 0.0.12 — 2024-03-01
- 0.0.11 — 2024-02-29
- 0.0.10 — 2024-02-27
- 0.0.9 — 2024-02-27
- 0.0.8 — 2024-02-23
- 0.0.7 — 2024-02-22
- 0.0.6 — 2024-02-20
- 0.0.5 — 2024-02-16
- 0.0.4 — 2024-02-13
- 0.0.3 — 2024-02-13
- 0.0.1 — 2024-02-07

## README

# Dopt AI Assistant React SDK

## Overview

The Dopt AI Assistant React SDK is a React framework-specific client for accessing Dopt's AI API. This SDK is a thin abstraction on top of [`@dopt/ai-assistant-javascript`](https://www.npmjs.com/package/@dopt/ai-assistant-javascript) and is useful mainly for wrapping asynchronous and streaming javascript functions into meaningful React hooks.

The SDK lives in our open-source monorepo [odopt](https://github.com/dopt/odopt).

It is published to npm as [`@dopt/ai-assistant-react`](https://www.npmjs.com/package/@dopt/ai-assistant-react).

## Installation

Via npm:

```bash
npm install @dopt/ai-assistant-react
```

Via Yarn:

```bash
yarn add @dopt/ai-assistant-react
```

Via pnpm:

```bash
pnpm add @dopt/ai-assistant-react
```

## Configuration

To configure the Dopt provider you will need:

1. A AI API key (generated in Dopt)
1. A user identifier (user being an end-user you've identified to Dopt)

## Usage

### Initialization

You can initialize Dopt in your app by integrating the `<DoptAiProvider />` as follows:

```js
import { DoptAiProvider } from '@dopt/ai-assistant-react';
import Application from './application';

const rootElement = document.getElementById('root');
ReactDOM.render(
  <DoptAiProvider userId={userId} apiKey={aiApiKey}>
    <Application />
  </DoptAiProvider>,
  rootElement
);
```

### Hooks

- [useAssistant](./src/use-assistant.ts)

A hook for getting complete answers (and citations, if any) from an assistant given a `query` and / or `context`. This hook wraps the streaming API into a stateful abstraction which will be updated as more results are streamed from the AI API.

- [useSearch](./src/use-search.ts)

A hook for getting search results (a list of documents) from an assistant given a `query` and / or `context`. This hook wraps an async fetch request into a stateful abstraction which will be completed once the documents are returned from the search.

### Example usage

#### Accessing an AI Assistant

Using the [useAssistant](./src/use-assistant.ts) hook:

```tsx
import { useAssistant } from '@dopt/ai-assistant-react';
import { Modal } from '@your-company/modal';

export function Application() {
  const assistant = useAssistant('dopt-assistant', {
    query,
    context
  });

  return (
    <Modal>
      <div className='ai-assistant-content'>
        {assistant.content}
      <div>
      <div className='ai-assistant-documents'>
        {assistant.documents}
      <div>
    </Modal>
  );
}
```

## Feedback

Looking to provide feedback or report a bug? [Open an issue](https://github.com/dopt/odopt/issues/new?title=[@dopt/ai-assistant-react]%20) or contact us at [support@dopt.com](mailto:support@dopt.com).

## Contributing

All contributions are welcome! Feel free to open a [pull request](https://github.com/dopt/odopt/compare).

---
_Source: https://npm.io/package/@dopt/ai-assistant-react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
