# AI Assistant on Flutter

Nutrient AI Assistant brings AI chat capabilities to your documents, enabling users to ask questions in natural language and get answers without sifting through pages of text. AI Assistant is ideal for summarizing, translating, and finding certain information in documents. Users can tap links in the chat to jump to the part of the document information came from.

To use this feature, run [Nutrient AI Assistant][ai-assistant-guide] on your server.

## Setting up AI Assistant on Flutter

To get started, either implement AI Assistant in your own app by following the steps below, or check out the `nutrient_ai_assistant_example` in our [catalog app][].

1. Set up Nutrient AI Assistant on your server, or run the server locally. The easiest way to get started is to clone our [AI Assistant demo repository][ai-assistant-demo] and follow the instructions in the README.

2. Set an `AIAssistantConfiguration` in your main `PdfConfiguration`. This configuration specifies the URL where your AI Assistant server can be accessed, a JSON Web Token (JWT) for authentication, a session identifier, and an optional user identifier. It's best practice for the JWT to be [generated by your own server][generate-jwt]:

```dart
// Create AI Assistant configuration
final aiConfig = AIAssistantConfiguration(
  serverUrl: 'https://your-ai-assistant-server.com',
  jwt: 'your-jwt-token', // Generate this from your server
  sessionId: 'unique-session-id',
  userId: 'optional-user-id',
);

// Add to PDF configuration
final pdfConfig = PdfConfiguration(
  aiAssistantConfiguration: aiConfig,
  androidEnableAiAssistant: true,
  iOSLeftBarButtonItems: ['aiAssistantButtonItem'],
);
```

3. Add AI Assistant to your platform-specific UI:

   - **iOS**: Add `'aiAssistantButtonItem'` to `iOSLeftBarButtonItems` or `iOSRightBarButtonItems`
   - **Android**: Set `androidEnableAiAssistant: true`
   - **Web**: Add the AI Assistant button to your toolbar:

```dart
webConfiguration: PdfWebConfiguration(
  toolbarItems: [
    PspdfkitWebToolbarItem(type: PspdfkitWebToolbarItemType.aiAssistant),
    ...Pspdfkit.defaultWebToolbarItems,
  ],
),
```

When users tap the AI Assistant button, the document data will be uploaded to AI Assistant on your server, and the chat UI will be presented.

[catalog app]: https://github.com/PSPDFKit/pspdfkit-flutter/tree/master/example/lib
[ai-assistant-guide]: https://www.nutrient.io/guides/ai-assistant/
[ai-assistant-demo]: https://github.com/PSPDFKit/ai-assistant-demo
[generate-jwt]: https://www.nutrient.io/guides/ai-assistant/viewer-integration/client-authentication/generate-a-jwt/
