Skip to content

Commit

Permalink
Merge pull request #6 from elimu-ai/4-chat-ui
Browse files Browse the repository at this point in the history
feat: #4 Chat UI
  • Loading branch information
jo-elimu authored Mar 30, 2024
2 parents 6ddf61c + 2b8201c commit 7c50884
Show file tree
Hide file tree
Showing 30 changed files with 791 additions and 359 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Gradle CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
java: [17]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java }}
- uses: gradle/gradle-build-action@v2
- run: chmod +x gradlew
- run: ./gradlew clean
# - run: ./gradlew build
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@

## Code

### Build

Set `apiKey=<value>` in `local.properties`

```
./gradlew clean
./gradlew build
```

...

## Submission Details
Expand Down
66 changes: 30 additions & 36 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
}

android {
namespace = "ai.elimu.soga"
namespace = "com.google.ai.soga"
compileSdk = 34

defaultConfig {
applicationId = "ai.elimu.soga"
minSdk = 34
applicationId = "com.google.ai.soga"
minSdk = 26
targetSdk = 34
versionCode = 1000000
versionName = "1.0.0"
Expand All @@ -20,15 +21,6 @@ android {
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -40,30 +32,32 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
kotlinCompilerExtensionVersion = "1.5.4"
}
}

dependencies {
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2")
implementation("androidx.activity:activity-compose:1.8.1")
implementation("androidx.navigation:navigation-compose:2.7.5")

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")

implementation("io.coil-kt:coil-compose:2.5.0")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")

implementation("com.google.ai.client.generativeai:generativeai:0.2.2")
}
24 changes: 0 additions & 24 deletions app/src/androidTest/java/ai/elimu/soga/ExampleInstrumentedTest.kt

This file was deleted.

7 changes: 3 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Soga">
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Soga">
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -24,4 +23,4 @@
</activity>
</application>

</manifest>
</manifest>
46 changes: 0 additions & 46 deletions app/src/main/java/ai/elimu/soga/MainActivity.kt

This file was deleted.

70 changes: 0 additions & 70 deletions app/src/main/java/ai/elimu/soga/ui/theme/Theme.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.google.ai.soga

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewmodel.CreationExtras
import com.google.ai.client.generativeai.GenerativeModel
import com.google.ai.client.generativeai.type.generationConfig
import com.google.ai.soga.feature.chat.ChatViewModel

val GenerativeViewModelFactory = object : ViewModelProvider.Factory {
override fun <T : ViewModel> create(
viewModelClass: Class<T>,
extras: CreationExtras
): T {
val config = generationConfig {
temperature = 0.7f
}

return with(viewModelClass) {
when {
isAssignableFrom(ChatViewModel::class.java) -> {
// Initialize a GenerativeModel with the `gemini-pro` AI model for chat
val generativeModel = GenerativeModel(
modelName = "gemini-1.0-pro",
apiKey = BuildConfig.apiKey,
generationConfig = config
)
ChatViewModel(generativeModel)
}

else ->
throw IllegalArgumentException("Unknown ViewModel class: ${viewModelClass.name}")
}
} as T
}
}
44 changes: 44 additions & 0 deletions app/src/main/kotlin/com/google/ai/soga/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.google.ai.soga

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.google.ai.soga.feature.chat.ChatRoute
import com.google.ai.soga.ui.theme.GenerativeAISample

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
GenerativeAISample {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
val navController = rememberNavController()

NavHost(navController = navController, startDestination = "menu") {
composable("menu") {
MenuScreen(onItemClicked = { routeId ->
navController.navigate(routeId)
})
}
composable("chat") {
ChatRoute()
}
}
}
}
}
}
}
Loading

0 comments on commit 7c50884

Please sign in to comment.