Skip to content

Commit

Permalink
Merge pull request #3
Browse files Browse the repository at this point in the history
Initial working version
  • Loading branch information
BottleRocket-Colin authored May 22, 2024
2 parents 43b78fa + 74294b8 commit 6d582f3
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 110 deletions.
1 change: 0 additions & 1 deletion .github/auto_assign.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ reviewers:
- br-Emery
- BottleRocket-Colin
- harishrpatel
- MMurrayAtBR

# A list of keywords to be skipped the process that add reviewers if pull requests include it
skipKeywords:
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ name: Gradle Package
on:
push:
branches: [ "deploy" ]
# pull_request:
# branches: [ "deploy" ]

jobs:
build:

build:
runs-on: macOS-latest
timeout-minutes: 30
permissions:
contents: read
packages: write
Expand All @@ -35,6 +34,9 @@ jobs:
uses: gradle/gradle-build-action@v2.11.0
with:
arguments: build
env:
GH_READ_USERNAME: ${{ secrets.REPO_READ_USER }}
GH_READ_PASSWORD: ${{ secrets.REPO_READ_TOKEN }}

# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
# the publishing section of your build.gradle
Expand All @@ -43,4 +45,5 @@ jobs:
with:
arguments: publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_PUBLISH_USERNAME: ${{ secrets.REPO_READ_WRITE_USER }}
GH_PUBLISH_PASSWORD: ${{ secrets.REPO_READ_WRITE_TOKEN }}
22 changes: 12 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
[versions]
agp = "8.4.0-alpha13"
dokka = "1.9.10"
kotlin = "1.9.21"
ktLint-gradle = "11.6.1"
kermit = "2.0.2"
ktor = "2.3.6"
ksp = "1.9.20-1.0.14"
#Publishing Version
launchpad-ai = "0.1.0"

# Versioning for build scripts
# Android SDK versions
compile-sdk = "34"
min-sdk = "24"
launchpad-ai = "0.0.1"

# Dependcy versions
agp = "8.5.0-beta02"
dokka = "1.9.10"
kotlin = "1.9.22"
ktLint-gradle = "11.6.1"
ktor = "2.3.10"
ksp = "1.9.22-1.0.17"


[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kermit = { module = "co.touchlab:kermit", version.ref = "kermit" }

ktor = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" }
ktor-client-android = { module = "io.ktor:ktor-client-android", version.ref = "ktor" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jan 17 13:18:58 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
14 changes: 4 additions & 10 deletions kmp-launchpad-ai/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,16 @@ kotlin {

androidTarget {
publishAllLibraryVariants()

compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
jvmToolchain(17)
jvm("desktop")

iosX64()
iosArm64()
iosSimulatorArm64()

sourceSets {
commonMain.dependencies {
implementation(libs.kermit)

implementation(libs.ktor)
implementation(libs.ktor.content.negotiation)
implementation(libs.ktor.logging)
Expand Down Expand Up @@ -72,8 +66,8 @@ publishing {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/BottleRocketStudios/KMP-LaunchPad-AI")
credentials {
username = System.getenv("REPO_READ_WRITE_USER")
password = System.getenv("REPO_READ_WRITE_TOKEN")
username = System.getenv("REPO_READ_WRITE_USER") ?: System.getenv("GH_PUBLISH_USERNAME")
password = System.getenv("REPO_READ_WRITE_TOKEN") ?: System.getenv("GH_PUBLISH_PASSWORD")
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.br.kmplaunchpadai.data.converters

import com.br.kmplaunchpadai.data.model.ContentDto
import com.br.kmplaunchpadai.data.model.FunctionCallDto
import com.br.kmplaunchpadai.data.model.FunctionDeclarationDto
import com.br.kmplaunchpadai.data.model.FunctionResponseDto
import com.br.kmplaunchpadai.data.model.ParametersDto
Expand All @@ -9,6 +10,7 @@ import com.br.kmplaunchpadai.data.model.PropertyDto
import com.br.kmplaunchpadai.data.model.ResponseDto
import com.br.kmplaunchpadai.domain.mediator.GeminiContent
import com.br.kmplaunchpadai.domain.mediator.GeminiFunction
import com.br.kmplaunchpadai.domain.mediator.GeminiFunctionCall
import com.br.kmplaunchpadai.domain.mediator.GeminiParameter
import com.br.kmplaunchpadai.domain.mediator.GeminiPart
import com.br.kmplaunchpadai.domain.mediator.GeminiResponse
Expand All @@ -21,25 +23,25 @@ fun GeminiContent.toDto() = ContentDto(
)

fun GeminiPart.toDto() = PartDto(
text = text ?: "",
// functionCall = functionCall?.functionCallDto(),
text = text,
functionCall = functionCall?.functionCallDto(),
functionResponse = functionResponse?.toDto()
)

// fun GeminiFunction.functionCallDto() = FunctionCallDto(
// name = name ?: "",
// args = parameters.associate { it.name to it.value?.toString().orEmpty() }
// )
fun GeminiFunctionCall.functionCallDto() = FunctionCallDto(
name = name,
args = args
)

fun GeminiResponse.toDto() = FunctionResponseDto(
name = name ?: "",
response = ResponseDto(
name = name ?: "",
content = content ?: emptyMap()
content = content
)
)

fun MutableList<GeminiFunction>.toFunctionDeclarationDto() = map { it.toDto() }
fun List<GeminiFunction>.toFunctionDeclarationDto() = map { it.toDto() }

fun GeminiFunction.toDto() = FunctionDeclarationDto(
description = description,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.br.kmplaunchpadai.data.model
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable


// Schema : https://ai.google.dev/api/rest/v1beta/models/generateContent
// TODO - add System instruction here for persona
@Serializable
data class ConversationRequestDto(
@SerialName("contents") val contents: List<ContentDto>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import kotlinx.serialization.Serializable
@Serializable
data class ConversationResponseDto(
@SerialName("candidates") val candidates: List<CandidateDto>,
@SerialName("usageMetadata") val usageMetadata: UsageMetadataDto
@SerialName("usageMetadata") val usageMetadata: UsageMetadataDto? = null
) : Dto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import kotlinx.serialization.Serializable

@Serializable
data class FunctionCallDto(
@SerialName("name") val name: String,
@SerialName("args") val args: Map<String, String>,
@SerialName("name") val name: String
) : Dto
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.br.kmplaunchpadai.data.model
import com.br.kmplaunchpadai.domain.mediator.GeminiResponseType
import kotlinx.serialization.Contextual
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive

@Serializable
data class ResponseDto(
@SerialName("content") val content: Map<String, @Contextual Any>,
@SerialName("content") val content: GeminiResponseType?,
@SerialName("name") val name: String
) : Dto
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.contentType

class GeminiService {
class GeminiService(private var apiKey: String = "KEY_NOT_INITIALIZED") {
private val client = ktorClient()
companion object {
// FIXME - USe Build config to drive API key
private const val API_KEY: String = "DUNNO_YET"
private const val URL = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$API_KEY"
}
private val url get() = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$apiKey"

suspend fun callGemini(payload: ConversationRequestDto): Result<ConversationResponseDto> =
runCatching {
client.post(URL) {
client.post(url) {
contentType(ContentType.Application.Json)
setBody(payload)
}.body<ConversationResponseDto>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.br.kmplaunchpadai.data.network

import com.br.kmplaunchpadai.domain.model.ApiException
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.HttpResponseValidator
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.defaultRequest
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logger
import io.ktor.client.plugins.logging.Logging
import io.ktor.http.URLProtocol
import io.ktor.http.isSuccess
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.json.Json

Expand All @@ -37,20 +33,6 @@ fun ktorClient(): HttpClient = HttpClient {
)
}

HttpResponseValidator {
validateResponse { response ->
if (!response.status.isSuccess()) {
val error: Error = response.body()
throw ApiException(
code = response.status.value,
message = error.message.toString(),
subCode = 0,
subMessage = "",
errorNumber = 0
)
}
}
}

defaultRequest {
url {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.br.kmplaunchpadai.domain

import com.br.kmplaunchpadai.domain.mediator.GeminiParametersType
import com.br.kmplaunchpadai.domain.mediator.GeminiResponseType

object ExampleFunctions {

fun findMovies(args: Map<String, Any>): Map<String, Any>? {
fun findMovies(args: GeminiParametersType): GeminiResponseType? {
return null
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.br.kmplaunchpadai.domain.mediator

import kotlinx.serialization.json.JsonElement
import kotlin.reflect.KFunction1


typealias GeminiParametersType = Map<String, String>
typealias GeminiResponseType = JsonElement
typealias GeminiFunctionType = KFunction1<GeminiParametersType, GeminiResponseType?>

/**
* Represents a Gemini function.
*/
class GeminiFunction {
var description: String = ""
var name: String = ""
var parameters: List<GeminiParameter> = emptyList()
private lateinit var functionReference: KFunction1<Map<String, Any>, Map<String, Any>?>
private lateinit var functionReference: GeminiFunctionType

/**
* Sets the name of the function.
Expand Down Expand Up @@ -47,7 +53,7 @@ class GeminiFunction {
*
* @param init A lambda that returns the function reference.
*/
fun functionReference(init: () -> KFunction1<Map<String, Any>, Map<String, Any>?>) {
fun functionReference(init: () -> GeminiFunctionType) {
functionReference = init()
}

Expand All @@ -56,5 +62,5 @@ class GeminiFunction {
*
* @return The result of the function call.
*/
fun call(params: Map<String, Any>) = functionReference.invoke(params)
fun call(params: GeminiParametersType) = functionReference.invoke(params)
}
Loading

0 comments on commit 6d582f3

Please sign in to comment.