> For the complete documentation index, see [llms.txt](https://edentech.gitbook.io/meetup/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edentech.gitbook.io/meetup/faqs/ai-generator.md).

# AI Generator

We added feature for AI chatbot and Image generator in recent version. To use this feature, you need to enable the AI option from your backend and add the Open AI Api key to your app for this feature to work.

## Enable AI feature from Backend

1. Login to the backend and click on the **Settings** menu
2. On the settings page, click on **App Settings**
3. On the App Settings page, scroll down to the AI Settings. Enable the **ai** feature you want, either **AI Chat** or **AI Image Generator** or **both option**. <br>

   <figure><img src="https://1451848172-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQBree38dhIotXdn4oz%2Fuploads%2FGA6RY7QV8MS5T7zPZ7ff%2Fimage.png?alt=media&amp;token=092b9140-7de3-4014-be4a-36e94814ab24" alt=""><figcaption></figcaption></figure>
4. then save the settings.

## Set OpenAI api key in app code

You need to get API key from your openAI bashboard. Checkout the link below on how to get your api key:\
<https://www.howtogeek.com/885918/how-to-get-an-openai-api-key/>

You need to set your api key in the mobile app source code for the ai feature to work on the mobile app.&#x20;

1. Create a **.env** file in the root of the flutter app folder. If there is a .env file in the root folder already then no need in create any one.
2. Open the **.env** file in the flutter app code.
3. Add a key name **OPENAI\_API\_KEY** and set your api key in there. Example below:\
   `OPENAI_API_KEY="sk-7sdsdsdC"`
4. save the .env file

Now, you need to run a command to so the app is aware of the new key you just set. The command is as stated below:

```
flutter pub run build_runner build
```

After the command has finished successfully, you can now run your app with no issue.

### AI Feature throws invalid api key error

When modifying the `.env` file, the generator might not pick up the change, if that happens simply clean the build cache and run the generator again.

```sh
dart run build_runner clean
dart run build_runner build --delete-conflicting-outputs
```
