Search code examples
androidkotlinopenai-api

Where can I find the definition of projects.openaiClient?


The following sample code comes from OpenAI API client for Kotlin project.

You can see it at https://github.com/aallam/openai-kotlin/tree/main/sample/native

I open the sample code with Android Studio, but I can't find where the author define the implementation(projects.openaiClient), I have searched the whole project, could you tell me ?

build.gradle.kts

plugins {
    kotlin("multiplatform")
}

kotlin {
    val hostOs = System.getProperty("os.name")
    val isMingwX64 = hostOs.startsWith("Windows")
    val nativeTarget = when {
        hostOs == "Mac OS X" -> macosX64("native")
        hostOs == "Linux" -> linuxX64("native")
        isMingwX64 -> mingwX64("native")
        else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
    }
    nativeTarget.apply {
        binaries {
            executable {
                entryPoint = "main"
            }
        }
    }
    sourceSets {
        val nativeMain by getting {
            dependencies {
                //implementation("com.aallam.openai:openai-client:<version>")
                implementation(projects.openaiClient)   // Where is projects.openaiClient
                implementation(libs.ktor.client.curl)   // Where is libs.ktor.client.curl
            }
        }
    }
}

Solution

  • The openai-client subproject is located here. The include was added in settings.gradle.kts.

    In the sample code the author then used something called type-safe project accessor:

    A project name with kebab case (some-lib) or snake case (some_lib) will be converted to camel case in accessors: projects.someLib.

    This means that the dependency can be added using projects.openaiClient.