With QuickBlox it’s easy to add iOS app features with AI. Whether you’re developing a chat app from scratch or choose to use our convenient iOS UI Kit, you can now utilize the QuickBlox iOS AI library to seamlessly integrate with OpenAI GPT to add exciting functionality.
We now offer AI Answer Assist. This feature allows app users to offer swift and accurate responses to user queries, by utilizing an OpenAI GPT model to analyze the context and provide relevant and concise answers in real-time. AI Answer Assist leads the way for iOS app user experience enhancement.
In the following tutorial we outline two approaches to implementing iOS in-app AI assistance:
I. Install our iOS AI library – QBAIAnswerAssistant – within your existing iOS project
II. Utilize our iOS UI Kit which already includes AI Answer Assist
QBAIAnswerAssistant can be installed using Swift Package Manager. To include it in your Xcode project, follow these steps:
To use QBAIAnswerAssistant in your project, follow these steps:
1. Import the QBAIAnswerAssistant module:
import QBAIAnswerAssistant
2. Create an array of Message objects representing the chat history:
let message1 = OwnerMessage("Hi there, how can I help you today?") let message2 = OpponentMessage("I need help with the iOS UI Kit. How do I set it up? ") let messages = [message1, message2]
3. Call the openAIAnswer method to generate an answer using an API key:
do { let apiKey = "YOUR_OPENAI_API_KEY" let answer = try await QBAIAnswerAssistant.openAIAnswer(to: messages, secret: apiKey) print("Generated Answer: \(answer)") } catch { print("Error: \(error)") }
Alternatively, you can use a QuickBlox user token and a proxy URL for more secure communication:
do { let qbToken = "YOUR_QUICKBLOX_USER_TOKEN" let proxyURL = "https://your-proxy-server-url" let answer = try await QBAIAnswerAssistant.openAIAnswer(to: messages, qbToken: qbToken, proxy: proxyURL) print("Generated Answer: \(answer)") } catch { print("Error: \(error)") }
To use the OpenAI API and generate answers, you need to obtain an API key from OpenAI. Follow these steps to get your API key:
Using a proxy server like the QuickBlox AI Assistant Proxy Server offers significant benefits in terms of security and functionality.
Enhanced Security:
Protection of API Keys:
Rate Limiting and Throttling:
Request Logging and Monitoring:
Flexibility and Customization:
SSL/TLS Encryption:
We have already integrated the AI Answer Assist feature within our iOS UI Kit. This feature allows you to generate answers in a chat, based on the chat history using the QBAIAnswerAssistant Swift package. This feature leverages the OpenAI API key or proxy server to generate responses more securely and efficiently.
To use the AI Assist Answer feature in your QuickBlox UI Kit project, follow these steps:
1. Enable the AI Assist Answer feature:
QuickBloxUIKit.feature.ai.assistAnswer.enable = true
If enabled, a button will appear next to each incoming message in the chat interface.
When the button is clicked, the Assist Answer feature will be launched, and a response will be generated, based on the chat history.
2. Set up the AI settings by providing either the OpenAI API key:
QuickBloxUIKit.feature.ai.answerAssist.apiKey = “YOUR_OPENAI_API_KEY”
Or set up with a proxy server:
QuickBloxUIKit.feature.ai.answerAssist.serverPath = “https://your-proxy-server-url”
We recommend using a proxy server like the QuickBlox AI Assistant Proxy Server, which offers significant benefits as outlined above.
A developer using the AI Answer Assist library has the ability to Default AIAnswerAssistSettings.
public class AIAnswerAssistSettings { /// Determines if assist answer functionality is enabled. public var enable: Bool = true /// The OpenAI API key for direct API requests (if not using a proxy server). public var apiKey: String = "" /// The URL path of the proxy server for more secure communication (if not using the API key directly). /// [QuickBlox AI Assistant Proxy Server](https://github.com/QuickBlox/qb-ai-assistant-proxy-server). public var serverPath: String = "" /// Represents the available API versions for OpenAI. public var apiVersion: QBAIAnswerAssistant.APIVersion = .v1 /// Optional organization information for OpenAI requests. public var organization: String? = nil /// Represents the available GPT models for OpenAI. public var model: QBAIAnswerAssistant.Model = .gpt3_5_turbo /// The temperature setting for generating responses (higher values make output more random). public var temperature: Float = 0.5 /// The maximum number of tokens to generate in the request. public var maxRequestTokens: Int = 3000 /// The maximum number of tokens to generate in the response. public var maxResponseTokens: Int? = nil }
A developer using the AI Answer Assist library has the ability to set up custom settings.
Below is an example of creating custom tones and installing them in QuickBlox iOS UI Kit from the custom application.
import QBAIAnswerAssistant // Setup custom settings for QBAIAnswerAssistant. QuickBloxUIKit.feature.ai.answerAssist.organization = "CustomDev" QuickBloxUIKit.feature.ai.answerAssist.model = .gpt4 QuickBloxUIKit.feature.ai.answerAssist.temperature = 0.8 QuickBloxUIKit.feature.ai.answerAssist.maxRequestTokens = 3500
Additional examples of setting custom settings for the appearance of user interface elements from a user application can be found in our UIKitSample.
Implementing the “AI Answer Assist” feature into your iOS chat app has never been easier. By following the straightforward steps outlined above you can seamlessly unlock the power of AI-driven interactions and provide your users with instantaneous, relevant, and context-aware responses.
QuickBlox’s commitment to crafting user-friendly tools and easy-to-implement software ensures that businesses across industries can harness the potential of AI without the complexity typically associated with such integrations.
QBAIPROXY Server – GitHub – QuickBlox/qb-ai-assistant-proxy-server
QBAIAnswerAssistant – GitHub – QuickBlox/ios-ai-answer-assistant
Documentation – AI Features | iOS UIKit | QuickBlox