Set up AI Assistant
This setup attaches AI Assistant directly to a document. If you need more control, refer to the advanced usage guide.
-
Set up Nutrient AI Assistant on your server, or run the server locally. The easiest way to get started is to clone Nutrient’s AI Assistant demo repository and follow the instructions in the README.
-
Add these dependencies to your Gradle file, as AI Assistant depends on them:
implementation("io.noties.markwon:core:4.6.2") implementation("io.noties.markwon:html:4.6.2") implementation("io.noties.markwon:linkify:4.6.2") implementation("io.noties.markwon:ext-tables:4.6.2") implementation("io.noties.markwon:ext-strikethrough:4.6.2") implementation("io.socket:socket.io-client:2.1.1")
-
Create an instance of AI Assistant using the
standaloneAiAssistant
method and passingAiAssistantConfiguration
into it. This configuration specifies the URL to access the AI Assistant server, a JSON Web Token (JWT) for authentication, a session identifier, and an optional user identifier.
Note:
-
It’s best practice for the JWT to be generated by your own server. For more details, refer to the guide on generating a JWT.
-
Use one session for each document if you want to restore the chat history each time. Use multiple sessions per document if multiple users access the same document in your app on one device.
-
Attach the AI Assistant object to
PdfDocument
by using thesetAiAssistant
method. -
To display the AI Assistant icon in your toolbar, enable it with
setAiAssistantEnabled
inPdfActivityConfiguration
.
Now you can access AI Assistant in your Activity by clicking the AI Assistant icon in the Nutrient MainToolbar
.
For an interactive example of AI Assistant, check out the
AiAssistant
example in the Catalog app.