Getting started with AI Assistant and Nutrient iOS SDK
AI Assistant provides Nutrient iOS SDK with AI functionality. Using intelligent document processing (IDP) technology, AI Assistant enables users to query, summarize, translate, compare document text on the fly.
To set up a fully functional AI system, you’ll need a Docker container service and a library working in unison:
- Nutrient iOS SDK — A document viewer for iOS that also exposes a user interface (UI) for the AI features.
- AI Assistant — A service to process the AI requests and process documents.
Prerequisites
AI Assistant is distributed as a Docker container. To run it on your computer, you need to install a Docker runtime distribution for your operating system.
Install and start Docker Desktop for Mac. Refer to the Docker website(opens in a new tab) for instructions.
Install and start Docker Desktop for Windows. Refer to the Docker website(opens in a new tab) for instructions.
Install and start Docker Engine. Refer to the Docker website(opens in a new tab) for instructions on how to install it for your Linux distribution.
After you install Docker, use these instructions(opens in a new tab) to install Docker Compose.
Obtaining an OpenAI API key
AI Assistant requires an API key from either of these LLM providers:
- OpenAI
- Azure OpenAI
This example will use OpenAI, but if you want to use Azure OpenAI, refer to the Azure OpenAI guide.
If you don’t have an OpenAI key, create one by following the steps in the next section. Otherwise, skip to the Setting up AI Assistant section.
Creating an OpenAI account
To create an OpenAI account, sign up(opens in a new tab) to obtain an API key(opens in a new tab).
The OpenAI API has attained SOC 2 Type 2 compliance (see the official announcement(opens in a new tab)).
Save your API key somewhere safe, as you’ll need it in the Setting up AI Assistant section.
Setting up AI Assistant
AI Assistant requires a PostgreSQL database with the pgvector(opens in a new tab) extension to operate.
Copy the code snippet below and save it anywhere on your computer in a file called docker-compose.yml
. Replace the <your-openai-api-key>
placeholder with your OpenAI API key:
version: "3.8"
services: ai-assistant: image: pspdfkit/ai-assistant:nightly environment: OPENAI_API_KEY: <your-openai-api-key> PGUSER: db-user PGPASSWORD: password PGDATABASE: ai_assistant PGHOST: db PGPORT: 5432 API_AUTH_TOKEN: secret JWT_PUBLIC_KEY: | -----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2gzhmJ9TDanEzWdP1WG+ 0Ecwbe7f3bv6e5UUpvcT5q68IQJKP47AQdBAnSlFVi4X9SaurbWoXdS6jpmPpk24 QvitzLNFphHdwjFBelTAOa6taZrSusoFvrtK9x5xsW4zzt/bkpUraNx82Z8MwLwr t6HlY7dgO9+xBAabj4t1d2t+0HS8O/ed3CB6T2lj6S8AbLDSEFc9ScO6Uc1XJlSo rgyJJSPCpNhSq3AubEZ1wMS1iEtgAzTPRDsQv50qWIbn634HLWxTP/UH6YNJBwzt 3O6q29kTtjXlMGXCvin37PyX4Jy1IiPFwJm45aWJGKSfVGMDojTJbuUtM+8P9Rrn AwIDAQAB -----END PUBLIC KEY----- JWT_ALGORITHM: RS256 DASHBOARD_USERNAME: dashboard DASHBOARD_PASSWORD: secret SECRET_KEY_BASE: secret-key-base ports: - 4000:4000 depends_on: db: condition: service_healthy db: image: pgvector/pgvector:pg16 healthcheck: test: [ "CMD-SHELL", "pg_isready -U db-user -d ai_assistant" ] interval: 3s timeout: 3s retries: 10 environment: POSTGRES_USER: db-user POSTGRES_PASSWORD: password POSTGRES_DB: ai_assistant POSTGRES_INITDB_ARGS: --data-checksums PGDATA: /var/lib/postgresql/data/pgdata volumes: - pgdata:/var/lib/postgresql/data
volumes: pgdata:
Starting AI Assistant
Now open a terminal emulator.
Use the terminal emulator integrated with your code editor or IDE. Alternatively, you can use Terminal.app
or iTerm2(opens in a new tab).
Use your code editor’s integrated terminal or PowerShell(opens in a new tab).
Use the terminal emulator integrated with your code editor or IDE, or one bundled with your desktop environment.
Go to the directory where you saved the docker-compose.yml
file:
cd <path-to-directory-with-docker-compose-yml>
Run the following:
docker-compose up
This command might take a while to run, depending on your internet connection speed. Wait until you see the following message in the terminal:
ai_document_assistant | info: AI Assistant started
AI Assistant is now up and running!
Setting up AI Assistant on iOS
To get started, either implement AI Assistant in your own app by following the steps below, or check out AIAssistantExample
(opens in a new tab) in our Catalog app(opens in a new tab). In the case of the latter, you don’t need to follow the steps below.
Set an
AIAssistantConfiguration
in your mainPDFConfiguration
. 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; for more details, refer to generate a JWT in our AI Assistant server guides. You may have one session for each document if you want to restore the chat history each time. You could have multiple sessions per document if multiple users access the same document in your app on one device.Add
AIAssistantButton
(SwiftUI) oraiAssistantButtonItem
(UIKit) to your navigation bar or toolbar. When users tap this button, the document data will be uploaded to AI Assistant on your server, and the chat UI will be presented.