AI Features
Overview
QuickBlox AI for Android provides a range of features to enhance the chat experience. With essential messaging functionalities such as answer assistant, users can engage in more interactive conversations, and AI Translate can improve cross-language communication.
Supported features
name | description |
---|---|
Answer assistant | Provides answers based on chat history |
AI Translate | Provides translation of chat message |
AI Rephrase | Provides multiple variants of text |
Answer assistant
QuickBlox provides answer assistant functionality that helps users effortlessly send various answers considering chat history. The library is based on OpenAI functional and provides the simplest way to communicate with API.

How to use
There are 2 easy steps to implement the QuickBlox AI Answer Assistant feature in any Android application.
- Add repository and dependency
- Invoke necessary method from the entry point and pass the data
Add the repository
First of all, you need to add the repository to existing Android application. You need to open the gradle (root level) file and add the code like in the snippet below in dependencyResolutionManagement section
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// below we have the a link to QuickBlox AI repository
maven {
url "https://github.com/QuickBlox/android-ai-releases/raw/main/"
}
}
}
Add the dependency
Next, you need to add a dependency to existing Android application. You need to open the gradle(application level) file and add the code like in the snippet below in dependencies section.
dependencies {
// some another dependencies
// below we have a link to QuickBlox AI Answer assistant library
implementation "com.quickblox:android-ai-answer-assistant:1.0.0"
}
Version 1.0.0 can be changed according to the last release from a repository. The last release or all release history you can see in our repository https://github.com/QuickBlox/android-ai-releases/releases
Invoke code and pass data
The QuickBlox AI Answer Assistant can be used by 2 approaches.
- Directly. Using the library with raw Open AI token. Of course, the token should be hidden with the best approach. For example, add the token to the local.properties file. The library will communicate directly with OpenAI Api. This is not preferred way because we using Open AI token directly. It's a good solution for development flow, not for release.
- Proxy. Using the library with QuickBlox session token and with a proxy server. The library will communicate through a proxy server (not directly) with OpenAI Api. This is the preferred safety way because we encapsulate the Open AI token inside the proxy server. It's a good solution for release flow.
Directly using
There are two approaches to directly using.
- Async - when the library is responsible for async working. You don't need to switch between threads.
- Sync - when the library executes only in a thread where the library was invoked. You need to add the switching between threads with your hands.
To invoke the QuickBlox answer assistant library method you need to add necessary imports and invoke the executeByOpenAITokenAsync or executeByOpenAITokenSync method like in the code snippet below.
// some another imports
// below we have required imports for QuickBlox answer assistant library
import com.quickblox.android_ai_answer_assistant.QBAIAnswerAssistant
import com.quickblox.android_ai_answer_assistant.callback.CallbackImpl
import com.quickblox.android_ai_answer_assistant.exception.QBAIAnswerAssistantException
import com.quickblox.android_ai_answer_assistant.message.Message
import com.quickblox.android_ai_answer_assistant.message.OpponentMessage
import com.quickblox.android_ai_answer_assistant.message.OwnerMessage
/*
* some code
*/
private fun answerAssistantByOpenAITokenAsync() {
val openAIToken = "open_ai_token" // our raw open ai token
val messages = mutableListOf<Message>() // messages history
QBAIAnswerAssistant.executeByOpenAITokenAsync(openAIToken, messages, object : CallbackImpl() {
override fun onComplete(answers: List<String>) {
// here will be result as list of answers
}
override fun onError(error: QBAIAnswerAssistantException) {
// oops, something goes wrong
}
})
}
private fun answerAssistantByOpenAITokenSync() {
val openAIToken = "open_ai_token" // our raw open ai token
val messages = mutableListOf<Message>() // messages history
try {
QBAIAnswerAssistant.executeByOpenAITokenSync(openAIToken, messages)
} catch (exception: QBAIAnswerAssistantException) {
// need to handle exception if we need
}
}
parameter name | type | description |
---|---|---|
openAIToken | String | The token for access to OpenAI API |
messages | List | The list of messages (chat history) |
Proxy using
- Async - when the library is responsible for async working. You don't need to switch between threads.
- Sync - when the library executes only in a thread where the library was invoked. You need to add the switching between threads with your hands.
To invoke the QuickBlox answer assistant library method you need to add necessary imports and invoke the executeByQBTokenAsync or executeByQBTokenSync method like in the code snippet below.
// some another imports
// below we have required imports for QuickBlox answer assistant library
import com.quickblox.android_ai_answer_assistant.QBAIAnswerAssistant
import com.quickblox.android_ai_answer_assistant.callback.CallbackImpl
import com.quickblox.android_ai_answer_assistant.exception.QBAIAnswerAssistantException
import com.quickblox.android_ai_answer_assistant.message.Message
import com.quickblox.android_ai_answer_assistant.message.OpponentMessage
import com.quickblox.android_ai_answer_assistant.message.OwnerMessage
/*
* some code
*/
private fun answerAssistantAsync() {
val qbToken = "quickblox_token" // our QuickBlox session token
val serverProxyUrl = "https://my.proxy-server.com" // our proxy server url
val messages = mutableListOf<Message>() // messages history
QBAIAnswerAssistant.executeByQBTokenAsync(qbToken, serverProxyUrl, messages, object : CallbackImpl() {
override fun onComplete(answers: List<String>) {
// here will be result as list of answers
}
override fun onError(error: QBAIAnswerAssistantException) {
// oops, something goes wrong
}
}, allowAllCerts = false)
}
private fun answerAssistantSync() {
val qbToken = "quickblox_token" // our QuickBlox session token
val serverProxyUrl = "https://my.proxy-server.com" // our proxy server url
val messages = mutableListOf<Message>() // messages history
try {
QBAIAnswerAssistant.executeByQBTokenSync(qbToken, serverProxyUrl, messages, allowAllCerts = false)
} catch (exception: QBAIAnswerAssistantException) {
// need to handle exception if we need
}
}
parameter name | type | description |
---|---|---|
qbToken | String | The QuickBlox session token |
serverProxyUrl | String | The URL of a proxy server |
messages | List | The list of messages (chat history) |
allowAllCerts | Boolean | The optional parameter to allow the library to trust all certs from the Proxy server (please use it parameter only for the development process, not for release), by default is set to false |
We recommended using our proxy server which you can find by link https://github.com/QuickBlox/qb-ai-assistant-proxy-server/releases Please use the latest release.
Messages history
The are two types of messages, OpponentMessage and OwnerMessage. Both messages inherited the Message interface
- OpponentMessage - the message from opponent who have a chat with us.
- OwnerMessage - the message from ourselves. It's who needs to send answers using the QuickBlox Answer Assistant library.
We need to pass the message history as a List where the messages were added in ascending type, The first element in list should be the last received message. The good practice is to use the last message from an opponent, it will be the first element of our messages chain List. In the picture below we have an example of messages order.

You need to create a list of Message interfaces by OwnerMessage and OpponentMessage models (implementation Message interface) like in the code snippet below with chat history.
private fun generateMessageHistory(): List<Message> {
val messages = mutableListOf<Message>()
// it's our last message, will be insert with index 0
messages.add(OwnerMessage("Hi. let me check..."))
// it's last message from opponent, will be insert with index 1
messages.add(OpponentMessage("Can we have a call today evening?"))
// it's message from opponent, will be insert with index 2
messages.add(OpponentMessage("I've a question about your job"))
// it's message from opponent, will be insert with index 3
messages.add(OpponentMessage("How are you?"))
// it's our message, will be insert with index 4
messages.add(OwnerMessage("Hello"))
// it's first message from opponent, will be insert with index 5
messages.add(OpponentMessage("Hello"))
return messages
}
Exception
In the QuickBlox answer assistant library you could receive QBAIAnswerAssistantException in onError callback for async and throwing it fromsync approaches. To get details information you can get it from message field like in the code snippet below.
// async approach
override fun onError(error: QBAIAnswerAssistantException) {
val detailMessage = error.message
// show message to UI or another logic
}
// sync approach
try {
// invoke sync methods from QBAIAnswerAssistant
} catch (exception: QBAIAnswerAssistantException) {
val detailMessage = exception.message
// show message to UI or another logic
}
AI Translate
QuickBlox provides Translate functionality that helps users simplify cross-lingual communication by providing instant message translation services. The library is based on OpenAI functional and provides the simplest way to communicate with API.

How to use
There are 2 easy steps to implement the QuickBlox AI Translate library in any Android application.
- Add repository and dependency
- Invoke the necessary method from the entry point and pass the data
Add the repository
First of all, you need to add the repository to the existing Android application. You need to open the gradle (root level) file and add the code like in the snippet below in the dependencyResolutionManagement section
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// below we have the a link to QuickBlox AI repository
maven {
url "https://github.com/QuickBlox/android-ai-releases/raw/main/"
}
}
}
Add the dependency
Next, you need to add a dependency to the existing Android application. You need to open the gradle(application level) file and add the code like in the snippet below in the dependencies section.
dependencies {
// some another dependencies
// below we have a link to QuickBlox AI Translate library
implementation "com.quickblox:ai-translate:1.0.0"
}
Version 1.0.0 can be changed according to the last release from a repository. The last release or all release history you can see in our repository https://github.com/QuickBlox/android-ai-releases/releases
Invoke code and pass data
The QuickBlox AI Translate can be used by 2 approaches.
- Directly. Using the library with raw Open AI token. Of course, the token should be hidden with the best approach. For example, add the token to the local.properties file. The library will communicate directly with OpenAI Api. This is not the preferred way because we using Open AI token directly. It's a good solution for development flow, not for release.
- Proxy. Using the library with QuickBlox session token and with a proxy server. The library will communicate through a proxy server (not directly) with OpenAI Api. This is the preferred safety way because we encapsulate the Open AI token inside the proxy server. It's a good solution for release flow.
Directly using
There are two approaches to directly using.
- Async - when the library is responsible for async working. You don't need to switch between threads.
- Sync - when the library executes only in a thread where the library was invoked. You need to add the switching between threads with your hands.
To invoke the QuickBlox AI Translate library method you need to add necessary imports and invoke the executeByOpenAIToken method like in the code snippet below.
// some another imports
// below we have required imports for QuickBlox AI Tanslate library
import com.quickblox.android_ai_translate.QBAITranslate
import com.quickblox.android_ai_translate.callback.CallbackImpl
import com.quickblox.android_ai_translate.exception.QBAITranslateException
import com.quickblox.android_ai_translate.message.AITranslateMessageImpl
/*
* some code
*/
private fun translateByOpenAITokenAsync() {
val openAIToken = "open_ai_token" // our raw open ai token
val text = "The text to translate
QBAITranslate.executeByOpenAITokenAsync(openAIToken, text, object : CallbackImpl() {
override fun onComplete(translations: List<String>) {
// here will be result as list of translations
}
override fun onError(error: QBAITranslateException) {
// oops, something goes wrong
}
})
}
private fun translateByOpenAITokenSync() {
val openAIToken = "open_ai_token" // our raw open ai token
val text = "The text to translate
try {
val translations = QBAITranslate.executeByOpenAITokenSync(openAIToken, text)
} catch (exception: QBAITranslateException) {
// need to handle exception if we need
}
}
parameter name | type | description |
---|---|---|
openAIToken | String | The token for access to OpenAI API |
text | String | The text to translate |
Proxy using
- Async - when the library is responsible for async working. You don't need to switch between threads.
- Sync - when the library executes only in a thread where the library was invoked. You need to add the switching between threads with your hands.
To invoke the QuickBlox AI Translate library method you need to add necessary imports and invoke the executeByQBToken method like in the code snippet below.
// some another imports
// below we have required imports for QuickBlox AI Translate library
import com.quickblox.android_ai_translate.QBAITranslate
import com.quickblox.android_ai_translate.callback.CallbackImpl
import com.quickblox.android_ai_translate.exception.QBAITranslateException
import com.quickblox.aandroid_i_translate.message.AITranslateMessageImpl
/*
* some code
*/
private fun translateByQBTokenAsync() {
val qbToken = "quickblox_token" // our QuickBlox session token
val serverProxyUrl = "https://my.proxy-server.com" // our proxy server url
val text = "The text to translate"
QBAITranslate.executeByQBTokenAsync(qbToken, serverProxyUrl, text, object : CallbackImpl() {
override fun onComplete(translations: List<String>) {
// here will be result as list of translations
}
override fun onError(error: QBAITranslateException) {
// oops, something goes wrong
}
}, allowAllCerts = false)
}
private fun translateByQBTokenSync() {
val qbToken = "quickblox_token" // our QuickBlox session token
val serverProxyUrl = "https://my.proxy-server.com" // our proxy server url
val text = "The text to translate
try {
val translations = QBAITranslate.executeByQBTokenSync(qbToken, serverProxyUrl, text, allowAllCerts = false)
} catch (exception: QBAITranslateException) {
// need to handle exception if we need
}
}
parameter name | type | description |
---|---|---|
qbToken | String | The QuickBlox session token |
serverProxyUrl | String | The URL of a proxy server |
text | String | The text to translate |
allowAllCerts | Boolean | The optional parameter to allow the library to trust all certs from the Proxy server (please use it parameter only for the development process, not for release), by default is set to false |
We recommended using our proxy server which you can find by link https://github.com/QuickBlox/qb-ai-assistant-proxy-server/releases Please use the latest release.
Exception
In the QuickBlox AI Translate library you could receive QBAITranslateException in onError callback for async and throw it from sync approaches. To get details information you can get it from the message field like in the code snippet below.
// async approach
override fun onError(error: QBAITranslateException) {
val detailMessage = error.message
// show message to UI or another logic
}
// sync approach
try {
// invoke sync methods from QBAITranslate
} catch (exception: QBAITranslateException) {
val detailMessage = exception.message
// show message to UI or another logic
}
AI Rephrase
QuickBlox provides AI Rephrase functionality that helps users effortlessly modify text with multiple variants. The library is based on OpenAI functional and provides the simplest way to communicate with API.
Add the repository
First of all, you need to add the repository to existing Android application. You need to open the gradle (root level) file and add the code like in the snippet below in dependencyResolutionManagement section
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// below we have the a link to QuickBlox AI repository
maven {
url "https://github.com/QuickBlox/android-ai-releases/raw/main/"
}
}
}
Add the dependency
Next, you need to add a dependency to existing Android application. You need to open the gradle(application level) file and add the code like in the snippet below in dependencies section.
dependencies {
// some another dependencies
// below we have a link to QuickBlox AI Answer assistant library
implementation "com.quickblox:android-ai-editing-assistant:1.0.0"
}
Version 1.0.0 can be changed according to the last release from a repository. The last release or all release history you can see in our repository https://github.com/QuickBlox/android-ai-releases/releases
Invoke code and pass data
The QuickBlox AI Rephrase can be used by 2 approaches.
- Directly. Using the library with raw Open AI token. Of course, the token should be hidden with the best approach. For example, add the token to the local.properties file. The library will communicate directly with OpenAI Api. This is not preferred way because we using Open AI token directly. It's a good solution for development flow, not for release.
- Proxy. Using the library with QuickBlox session token and with a proxy server. The library will communicate through a proxy server (not directly) with OpenAI Api. This is the preferred safety way because we encapsulate the Open AI token inside the proxy server. It's a good solution for release flow.
Directly using
There are two approaches to directly using.
- Async - when the library is responsible for async working. You don't need to switch between threads.
- Sync - when the library executes only in a thread where the library was invoked. You need to add the switching between threads with your hands.
To invoke the QuickBlox AI Rephrase library method you need to add necessary imports and invoke the executeByOpenAITokenAsync or executeByOpenAITokenSync method like in the code snippet below.
// some another imports
// below we have required imports for QuickBlox AI Rephrase library
import com.quickblox.android_ai_editing_assistant.QBAIRephrase
import com.quickblox.android_ai_editing_assistant.callback.Callback
import com.quickblox.android_ai_editing_assistant.exception.QBAIRephraseException
import com.quickblox.android_ai_editing_assistant.model.QBAIRephraseToneImpl
/*
* some code
*/
private fun rephraseByOpenAITokenAsync() {
QBAIRephrase.init(context)
val openAIToken = "open_ai_token" // our raw open ai token
val tone = QBAIRephraseToneImpl("professional") // our tone
val text = "Hi Bro. I have problem, need you help! Can you call me?" // our text for rephrase
QBAIRephrase.executeByOpenAITokenAsync(openAIToken, tone, text, object : CallbackImpl() {
override fun onComplete(result: List<String>) {
// here will be result as list of rephrase results
}
override fun onError(error: QBAIRephraseException) {
// oops, something goes wrong
}
})
}
private fun rephraseByOpenAITokenSync() {
QBAIRephrase.init(context)
val openAIToken = "open_ai_token" // our raw open ai token
val tone = QBAIRephraseToneImpl("professional") // our tone
val text = "Hi Bro. I have problem, need you help! Can you call me?" // our text for rephrase
try {
QBAIRephrase.executeByOpenAITokenSync(openAIToken, tone, text)
} catch (exception: QBAIRephraseException) {
// need to handle exception if we need
}
}
parameter name | type | description |
---|---|---|
openAIToken | String | The token for access to OpenAI API |
tone | QBAIRephraseTone | The Tone object |
text | String | The text which will be rephrased |
Proxy using
- Async - when the library is responsible for async working. You don't need to switch between threads.
- Sync - when the library executes only in a thread where the library was invoked. You need to add the switching between threads with your hands.
To invoke the QuickBlox AI Rephrase library method you need to add necessary imports and invoke the executeByQBTokenAsync or executeByQBTokenSync method like in the code snippet below.
// some another imports
// below we have required imports for QuickBlox AI Rephrase library
import com.quickblox.android_ai_editing_assistant.QBAIRephrase
import com.quickblox.android_ai_editing_assistant.callback.Callback
import com.quickblox.android_ai_editing_assistant.exception.QBAIRephraseException
import com.quickblox.android_ai_editing_assistant.model.QBAIRephraseToneImpl
/*
* some code
*/
private fun rephraseByQBTokenAsync() {
QBAIRephrase.init(context)
val qbToken = "quickblox_token" // our QuickBlox session token
val serverProxyUrl = "https://my.proxy-server.com" // our proxy server url
val tone = QBAIRephraseToneImpl("professional") // our tone
val text = "Hi Bro. I have problem, need you help! Can you call me?" // our text for rephrase
QBAIRephrase.executeByQBTokenAsync(qbToken, serverProxyUrl, tone, text, object : CallbackImpl() {
override fun onComplete(result: List<String>) {
// here will be result as list of rephrase results
}
override fun onError(error: QBAIRephraseException) {
// oops, something goes wrong
}
}, allowAllCerts = false)
}
private fun rephraseByQBTokenSync() {
QBAIRephrase.init(context)
val qbToken = "quickblox_token" // our QuickBlox session token
val serverProxyUrl = "https://my.proxy-server.com" // our proxy server url
val tone = QBAIRephraseToneImpl("professional") // our tone
val text = "Hi Bro. I have problem, need you help! Can you call me?" // our text for rephrase
try {
QBAIRephrase.executeByQBTokenSync(qbToken, serverProxyUrl, tone, text, allowAllCerts = false)
} catch (exception: QBAIRephraseException) {
// need to handle exception if we need
}
}
parameter name | type | description |
---|---|---|
qbToken | String | The QuickBlox session token |
serverProxyUrl | String | The URL of a proxy server |
tone | QBAIRephraseTone | The tone object |
allowAllCerts | Boolean | The optional parameter to allow the library to trust all certs from the Proxy server (please use it parameter only for the development process, not for release), by default is set to false |
We recommended using our proxy server which you can find by link https://github.com/QuickBlox/qb-ai-assistant-proxy-server/releases Please use the latest release.
Exception
In the QuickBlox AI Rephrase library you could receive QBAIRephraseException in onError callback for async and throwing it fromsync approaches. To get details information you can get it from message field like in the code snippet below.
// async approach
override fun onError(error: QBAIRephraseException) {
val detailMessage = error.message
// show message to UI or another logic
}
// sync approach
try {
// invoke sync methods from QBAIRephrase
} catch (exception: QBAIRephraseException) {
val detailMessage = exception.message
// show message to UI or another logic
}
Updated 26 days ago