AI Assistant
The exposed functionality from AI Assistant is designed to be integrated with Nutrient MAUI SDK. This guide explains how to connect the two to provide your users with an AI experience.
Configuration
To show the AI Assistant user interface (UI) on Nutrient MAUI SDK, you first need to configure the AI Assistant configuration with a generated JSON Web Token (JWT) while loading a document via the ViewerConfiguration
object:
try { var config = PSPDFKitController.CreateViewerConfiguration(); config.SetAIAssistantConfiguration("<sessionId>", "<jwt>", "<backendUrl>"); await PSPDFKitController.LoadDocumentFromAssetsAsync( DemoFile, config); PSPDFKitController.MainToolbar.ToolbarItems.Add(new AIAssistantButton()); } catch (Exception ex) { RaiseExceptionThrownEvent("Loading document failed", ex); }
Replace the <sessionId>
placeholder in the code above with an alphanumeric unique ID generated by your application. A new ID will open a new chat session, and an existing ID will reopen the session where the user left off.
Replace the <jwt>
placeholder with a valid and signed JWT. See the guide on generating a JWT for details.
Replace the <backendUrl>
placeholder with the full URL where your AI Assistant service is served from. This will be the protocol and the IP address or domain you’re hosting your service from, followed by the port number, e.g. http://localhost:4000
.
You can also pass an optional userId
to the aiAssistant
object, which will allow you to set a request limit for the user in the JWT, and to manage user data with the server API.
Opening the AI Assistant UI
To allow a user to show/hide the AI Assistant UI, you can add a toolbar button that will open the AI Assistant UI when clicked:
PSPDFKitController.MainToolbar.ToolbarItems.Add(new AIAssistantButton());
Programmatic opening
It’s also possible to show/hide the AI Assistant UI programmatically using the PDFView.ShowAIAssistant
dependency property:
<sdk:PDFView x:Name="PDFView" Initialized="OnPDFViewInitialized" ShowAIAssistant="true" />