> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quickblox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Features

> AI Features base on SmartChat Assistants

## Overview

Starting from version 2.20.0 of QuickBlox iOS SDK, the AI functionality is enabled and based on SmartChat Assistants. The QuickBlox iOS SDK 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.

**Supported features**

| Name             | Description                                                                |
| :--------------- | :------------------------------------------------------------------------- |
| AI Answer Assist | Generates a draft response based on chat history for the selected message. |
| AI Translate     | Provides translation based on chat history to selected incoming message.   |

## Requirements

The minimum requirements for using AI features are:

* QuickBlox iOS SDK v2.20.0
* QuickBlox account with activated SmartChat Assistants

Visit our [Key Concepts](doc:key-concepts) page to get an overall understanding of the most important QuickBlox concepts.

Visit our [Smart Chat Assistant overview](https://docs.quickblox.com/docs/smartchat-assistant-overview) page to get an overall understanding of the most important SmartChat Assistants concepts.

## Before you begin

1. Register a [QuickBlox account](https://admin.quickblox.com/signin). This is a matter of a few minutes and you will be able to use this account to build your apps.
2. Configure QuickBlox SDK for your app. Check out our [Setup](https://docs.quickblox.com/docs/ios-setup) page for more details.
3. Create a user session to be able to use QuickBlox functionality. See our [Authentication](https://docs.quickblox.com/docs/ios-authentication) page to learn how to do it.
4. Create or update your SmartChat Assistant. See our [Smart Chat Assistant](https://docs.quickblox.com/docs/smartchat-assistant-overview#create-smartchat-assistant) documentation to learn how to do it.

### Enable AI Extensions

1. Navigate to the **Dashboard => *YOUR\_APP* => AI Extensions** page
2. Select the checkboxes for the features you want to enable.
3. Click the Save button to save changes.

<img src="https://mintcdn.com/quickblox/xkS1X1sSZwktmwsY/images/android-sdk-ai.png?fit=max&auto=format&n=xkS1X1sSZwktmwsY&q=85&s=d91bb0ccc4667c3045454d2123c09e78" className="centered-image" alt="Robot Icon" width="1706" height="705" data-path="images/android-sdk-ai.png" />

### Review your SmartChat Assistant

To get **ID** of SmartChat Assistant to use it as `smartChatAssistantId ` param follow the steps below:

1. Navigate to the **Dashboard => *YOUR\_APP* => SmartChat Assistant** page
2. Choose the ID of the SmartChat Assistant you want to update and click on it.
3. Edit the SmartChat Assistant settings.
4. Click the Save button to save changes.

<img src="https://mintcdn.com/quickblox/xkS1X1sSZwktmwsY/images/android-sdk-ai-2.png?fit=max&auto=format&n=xkS1X1sSZwktmwsY&q=85&s=4d0e056d1ca8f4bef2e5a1938a9ba935" className="centered-image" alt="Robot Icon" width="3278" height="1932" data-path="images/android-sdk-ai-2.png" />

## AI Answer Assist

QuickBlox AI Answer Assist generates a contextually relevant draft response based on the chat history. Use it to suggest replies that match the conversation context.

### How to use Assist Answer

<Tabs>
  <Tab title="Swift Concurrency">
    ```swift theme={null}
    let smartChatAssistantId = "XXXXXXXXXXXXXXXXXXXXXXXX"
    let messageToAssist = "What is Quickblox?"

    let history = [QBAIAnswerAssistHistoryMessage(role: .assistant, message: "History message"),
                   QBAIAnswerAssistHistoryMessage(role: .user, message: "Hi"),
                   QBAIAnswerAssistHistoryMessage(role: .assistant, message: "Hello! How can I assist you today?")
    ]

    let result = try await QB.ai.answerAssist(withSmartChatAssistantId: smartChatAssistantId,
                                              messageToAssist: messageToAssist,
                                              history: history)
    let answer = result.answer
    // handle answer
    ```
  </Tab>

  <Tab title="Swift">
    ```swift theme={null}
    let smartChatAssistantId = "XXXXXXXXXXXXXXXXXXXXXXXX"
    let messageToAssist = "What is Quickblox?"

    let history = [QBAIAnswerAssistHistoryMessage(role: .assistant, message: "History message"),
                   QBAIAnswerAssistHistoryMessage(role: .user, message: "Hi"),
                   QBAIAnswerAssistHistoryMessage(role: .assistant, message: "Hello! How can I assist you today?")
    ]

    QB.ai.answerAssist(withSmartChatAssistantId: smartChatAssistantId,
                       messageToAssist: messageToAssist,
                       history: history) { result, error in
        if let error = error {
            // handle error
            return
        }
        
        let answer = result.answer
        // handle answer
    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    NSString *smartChatAssistantId = @"XXXXXXXXXXXXXXXXXXXXXXXX";
    NSString *messageToAssist = @"What is Quickblox?";
        
    NSArray *history = @[
        [[QBAIAnswerAssistHistoryMessage alloc] initWithRole:QBAIRoleTypeAssistant message:@"History message"],
        [[QBAIAnswerAssistHistoryMessage alloc] initWithRole:QBAIRoleTypeUser message:@"Hi"],
        [[QBAIAnswerAssistHistoryMessage alloc] initWithRole:QBAIRoleTypeAssistant message:@"Hello! How can I assist you today?"]
    ];
        
    [QB.ai answerAssistWithSmartChatAssistantId:smartChatAssistantId
                                messageToAssist:messageToAssist
                                        history:history
                                     completion:^(id<QBAIAnswerAssistResultProtocol>  _Nonnull result, NSError * _Nullable error) {
        if (error) {
            // handle error
            return;
        }
            
        NSString *answer = result.answer;
        // handle answer
    }];
    ```
  </Tab>
</Tabs>

| Parameter name       | Type            | Description                                                                                                                                                                                                                                          |
| :------------------- | :-------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| smartChatAssistantId | String          | This field should hold your actual Smart Chat Assistant ID that you'll receive from the QuickBlox account. This ID is used to authenticate your requests to the AI service.                                                                          |
| messageToAssist      | String          | Message you want to get answer for.                                                                                                                                                                                                                  |
| history              | Array of Object | Conversation history. Used to add context. Each object of array should have the two fields: 'role' and 'message'. The field role should contains one of next values: 'user' or 'assistant'.  The field message should be a string with chat message. |

## AI Translate

QuickBlox offers translation functionality that helps users easily translate text messages in chat, taking into account the context of the chat history.

### How to use AI Translate

<Tabs>
  <Tab title="Swift Concurrency">
    ```swift theme={null}
    let smartChatAssistantId = "XXXXXXXXXXXXXXXXXXXXXXXX"
    let textToTranslate = "Hola!"
    let languageCode = "en"
            
    let result = try await QB.ai.translate(withSmartChatAssistantId: smartChatAssistantId,
                                           textToTranslate: textToTranslate,
                                           languageCode: languageCode)
    let answer = result.answer
    // handle answer
    ```
  </Tab>

  <Tab title="Swift">
    ```swift theme={null}
    let smartChatAssistantId = "XXXXXXXXXXXXXXXXXXXXXXXX"
    let textToTranslate = "Hola!"
    let languageCode = "en"
            
    QB.ai.translate(withSmartChatAssistantId: smartChatAssistantId,
                    textToTranslate: textToTranslate,
                    languageCode: languageCode) { result, error in
        if let error = error {
            // handle error
            return
        }
                
        let answer = result.answer
            // handle answer
    }
    ```
  </Tab>

  <Tab title="Objective-C">
    ```objc theme={null}
    NSString *smartChatAssistantId = @"XXXXXXXXXXXXXXXXXXXXXXXX";
    NSString *textToTranslate = @"Hola!";
    NSString *languageCode = @"en";
        
    [QB.ai translateWithSmartChatAssistantId:smartChatAssistantId
                             textToTranslate:textToTranslate
                                languageCode:languageCode
                                  completion:^(id<QBAITranslateResultProtocol>  _Nonnull result, NSError * _Nullable error) {
        if (error) {
            // handle error
            return;
        }
            
        NSString *answer = result.answer;
        // handle answer
    }];
    ```
  </Tab>
</Tabs>

| Parameter name       | Type   | Description                                                                                                                                                                 |
| :------------------- | :----- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| smartChatAssistantId | String | This field should hold your actual Smart Chat Assistant ID that you'll receive from the QuickBlox account. This ID is used to authenticate your requests to the AI service. |
| textToTranslate      | String | Text to translate.                                                                                                                                                          |
| languageCode         | String | Translation language code.                                                                                                                                                  |
