📖
AppKickstarter docs
  • Get Started
    • Get started
    • Initialize third parties
    • Project organization
    • Application initialization
  • Tech things
    • Multi modules Architecture
    • Dependency injection
    • Library management
    • Secrets and Build Config
    • Backend as an implementation detail
  • Tutorials
    • Add a login page
    • Add a screen with tab bars
    • Add a settings screen
    • Display an In-App Changelog for a new published version
    • Update localizations
    • Update theme
    • Customize onboarding
    • Setup your paywall
    • Setup your first notifications
    • Format dates and save on database
    • Using a Different Backend Instead of Firebase
    • Make an infinite list with pagination
  • Features
    • Onboarding
    • Authentication
    • Firebase support
    • Offline support
    • Monetization
    • Whats new feature
    • Navigation in AppKickstarter
    • Theme
    • UI Kit
    • Dates management
    • Platform specific
    • Offline cache
    • Translations
    • Analytics
    • User management
    • Logger
    • Platform utilities
    • Maps and locations
    • Secured AI Backend Proxy
    • Settings
    • Application monitoring
    • Notifications
  • UI Kit
    • Adaptive
    • Advanced Components
    • Animated Components
    • Badges
    • Buttons
    • Cards
    • Containers
    • Dialogs
    • EmptyStates
    • Icons
    • Images
    • Lists
    • Modals
    • Tabs
    • Texts
    • Text fields
    • Toasts
    • Toggles
  • Other
    • Known issues
Powered by GitBook
On this page
  • Publish Server (3 min setup)
  • Use AI module in a KMP Project (Android, iOS, Desktop, Web) (3 min setup)
  • Add AI module in a iOS Swift only Project
  • Add AI module in a Flutter Project

Was this helpful?

  1. Features

Secured AI Backend Proxy

We prevent you from losing thousands of dollars by including a backend that securely handles your API key requests to the AI API.

PreviousMaps and locationsNextSettings

Last updated 12 months ago

Was this helpful?

Publish Server (3 min setup)

  1. Login on render.com with your Github account

  2. Create a new Web Service

  1. In this repository you'll find a KMP ai client and a NodeJS backend server. Create a Github repository and push the node js part on it.

  2. Connect your new NodeJS repository to render and the web service you created before.

  3. On every push the render web service will be updated

  4. Add your environement variables: HMAC_SECRET_KEY, OPENAI_API_KEY and REPLICATE_API_TOKEN

Use AI module in a KMP Project (Android, iOS, Desktop, Web) (3 min setup)

  1. Copy paste AI module in your project

  2. Add module in settings.gradle:

include(":ai")
  1. Add dependency in your build.gradle:

kotlin {
    ...

    sourceSets {
        commonMain.dependencies { 
            implementation(projects.ai)
        }
    }
}
  1. Add environement variables in local.properties : mobile_ai_api_hmac_secret_key and mobile_ai_url.

mobile_ai_api_hmac_secret_key should be the same the Render HMAC_SECRET_KEY and mobile_ai_url is the url given by render when you publish your web service.

  1. Add BuildKonfig in your project:

import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING

plugins {
    ...
    id("com.codingfeline.buildkonfig")
}

buildkonfig {
    packageName = "your.package.app"

    val props = Properties()

    try {
        props.load(file("../local.properties").inputStream())
    } catch (e: Exception) {
        // keys are private and can not be committed to git
    }

    defaultConfigs {
        buildConfigField(
            STRING,
            "MOBILE_AI_API_HMAC_SECRET_KEY",
            props["mobile_ai_api_hmac_secret_key"]?.toString() ?: ""
        )

        buildConfigField(
            STRING,
            "MOBILE_AI_URL",
            props["mobile_ai_url"]?.toString() ?: ""
        )
    }
}
  1. Now you can call ChatGpt, Dall-e, Whisper, OpenAI Vision and more :

Create the service :

val aIService = AIService(
    BuildKonfig.MOBILE_AI_URL,
    BuildKonfig.MOBILE_AI_API_HMAC_SECRET_KEY,
)

Inject it in Koin:

module {
    singleOf { 
        AIService(
            BuildKonfig.MOBILE_AI_URL,
            BuildKonfig.MOBILE_AI_API_HMAC_SECRET_KEY,
        )
    } 
}

Call ChatGpt:

scope.launch {
    aiService
        .chatgpt(
            model = model, // support gpt3.5 turbo, gpt4, etc
            messages = listOf(
                Message(
                    role = "system",
                    content = "Marv is a factual chatbot that is also sarcastic."
                ),
                Message(
                    role = "user",
                    content = userContent
                ),
            )
        )
        .onFailure {
            result = "We found an error ${it.message}"
        }
        .onSuccess {
            result = it
        }
}

Call Dall-e 3

scope.launch {
    aiService
        .dallee(prompt) // only dall-e 3 for now but you can easily change it
        .onFailure { error = "We found an erorr ${it.message}" }
        .onSuccess { resultUrl = it.data.firstOrNull()?.url }
        .also { loading = false }
}

Call OpenAI Vision

scope.launch {
    aiService
        .vision(
            prompt = prompt,
            url = url // image url to analyze
        )
        .onFailure {
            result = "We found an error ${it.message}"
        }
        .onSuccess {
            result = it
        }
}

Add AI module in a iOS Swift only Project

You can add the module in a iOS Swift only project the same way you add a KMP library to a iOS Swift only app. If you want more informations please ask at hey@appkickstarter.com

Add AI module in a Flutter Project

You can add the module in a Flutter project the same way you add a KMP library to a Flutter app. If you want more informations please ask at hey@appkickstarter.com

Download the code on

Download AI module on

https://github.com/AppKickstarter/backend-ai
https://github.com/AppKickstarter/AI
Create a new Web Service in Render.com
Environment variables in Render.com