From 469270f407ab973c3f1f7d8227c747aebfd15aaa Mon Sep 17 00:00:00 2001 From: Lin <46208481+gy6543721@users.noreply.github.com> Date: Tue, 30 Jan 2024 10:50:24 +0900 Subject: [PATCH 1/5] [Update] Prompt modification - Modify Prompt - Upgrade Kotlin and Compiler version - Downgrade AGP to stable - Refine Code --- app/build.gradle.kts | 13 ++++++++----- .../lin/gemini/android/viewmodel/GeminiViewModel.kt | 6 +++--- gradle/libs.versions.toml | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e8c0e6c..2f72903 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -25,20 +25,23 @@ android { val properties = Properties() if (project.rootProject.file("local.properties").canRead()) { properties.load(project.rootProject.file("local.properties").inputStream()) - } - buildConfigField("String", "apiKey", "\"${properties.getProperty("API_KEY")}\"") + buildConfigField( + type = "String", + name = "apiKey", + value = "\"${properties.getProperty("API_KEY")}\"" + ) } buildTypes { release { isMinifyEnabled = false proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), + getDefaultProguardFile(name = "proguard-android-optimize.txt"), "proguard-rules.pro" ) - signingConfig = signingConfigs.getByName("debug") + signingConfig = signingConfigs.getByName(name = "debug") } } compileOptions { @@ -53,7 +56,7 @@ android { buildConfig = true } composeOptions { - kotlinCompilerExtensionVersion = "1.5.1" + kotlinCompilerExtensionVersion = "1.5.8" } packaging { resources { diff --git a/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt b/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt index cb9e8c0..3ee4e40 100644 --- a/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt +++ b/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt @@ -39,11 +39,11 @@ class GeminiViewModel( val deviceLanguage = Locale.getDefault().displayLanguage val textPrompt = - "Content:($inputText) \\n You are a lovely assistant. According to the provided content, " + "You are a lovely assistant. According to the provided text ($inputText), " val imagePrompt = - "Content:($inputText) \\n You are a lovely assistant. According to the provided images and content, " + "You are a lovely assistant. According to the provided images and text ($inputText), " val generalPrompt = - "if the content is a question, answer the question in $deviceLanguage. If the content is a request, respond with detailed information in $deviceLanguage." + "If the text is a question, answer the question in $deviceLanguage. If the text is a request, respond to the request in $deviceLanguage. If there is no text and only images are provided, describe the images in $deviceLanguage." val imageList = selectedImageBitmaps.value val inputContent = content { if (imageList.isNotEmpty()) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ebc7b66..4091d76 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -agp = "8.4.0-alpha07" -kotlin = "1.9.0" +agp = "8.2.2" +kotlin = "1.9.22" coreKtx = "1.12.0" junit = "4.13.2" junitVersion = "1.1.5" From 92bc718885ba0a87f910bbd263222b18f10c853d Mon Sep 17 00:00:00 2001 From: Lin <46208481+gy6543721@users.noreply.github.com> Date: Tue, 30 Jan 2024 11:11:46 +0900 Subject: [PATCH 2/5] [Update] Modify build gradle - Modify apiKey and related logic in build gradle - Update ReadMe --- README.md | 2 +- app/build.gradle.kts | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/README.md b/README.md index b4832c7..91dc42f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Please add your own API key into `local.properties` after cloning this app. You can get Gemini API key [here](https://ai.google.dev/). ``` -API_KEY=[your api key] +apiKey=[your api key] ``` ### Screenshots diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2f72903..1943e17 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -21,17 +21,6 @@ android { vectorDrawables { useSupportLibrary = true } - - val properties = Properties() - if (project.rootProject.file("local.properties").canRead()) { - properties.load(project.rootProject.file("local.properties").inputStream()) - } - - buildConfigField( - type = "String", - name = "apiKey", - value = "\"${properties.getProperty("API_KEY")}\"" - ) } buildTypes { From 7f8f9a683ecb9c0dcd9ad2c1cee2bb0796cb7b3d Mon Sep 17 00:00:00 2001 From: Lin <46208481+gy6543721@users.noreply.github.com> Date: Tue, 30 Jan 2024 11:29:43 +0900 Subject: [PATCH 3/5] [Fix] Prompt typo --- .../java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt b/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt index 3ee4e40..2efd338 100644 --- a/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt +++ b/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt @@ -43,7 +43,7 @@ class GeminiViewModel( val imagePrompt = "You are a lovely assistant. According to the provided images and text ($inputText), " val generalPrompt = - "If the text is a question, answer the question in $deviceLanguage. If the text is a request, respond to the request in $deviceLanguage. If there is no text and only images are provided, describe the images in $deviceLanguage." + "if the text is a question, answer the question in $deviceLanguage. If the text is a request, respond to the request in $deviceLanguage. If there is no text and only images are provided, describe the images in $deviceLanguage." val imageList = selectedImageBitmaps.value val inputContent = content { if (imageList.isNotEmpty()) { From ec6819fc0994cdffbd28e305e227a73d263f33c0 Mon Sep 17 00:00:00 2001 From: Lin <46208481+gy6543721@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:18:45 +0900 Subject: [PATCH 4/5] [Update] Prompt modification --- .../lin/gemini/android/viewmodel/GeminiViewModel.kt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt b/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt index 2efd338..f87da39 100644 --- a/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt +++ b/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt @@ -38,22 +38,16 @@ class GeminiViewModel( _uiState.value = GeminiUiState.Loading val deviceLanguage = Locale.getDefault().displayLanguage - val textPrompt = - "You are a lovely assistant. According to the provided text ($inputText), " - val imagePrompt = - "You are a lovely assistant. According to the provided images and text ($inputText), " - val generalPrompt = - "if the text is a question, answer the question in $deviceLanguage. If the text is a request, respond to the request in $deviceLanguage. If there is no text and only images are provided, describe the images in $deviceLanguage." + val prompt = + "$inputText (respond in $deviceLanguage)" val imageList = selectedImageBitmaps.value val inputContent = content { if (imageList.isNotEmpty()) { imageList.forEach { image -> image(image = image) } - text(text = imagePrompt + generalPrompt) - } else { - text(text = textPrompt + generalPrompt) } + text(text = prompt) } viewModelScope.launch { From 26f488626725ef6162a329f51b92b1e3a8f2457c Mon Sep 17 00:00:00 2001 From: Lin <46208481+gy6543721@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:54:51 +0900 Subject: [PATCH 5/5] [Release] 0.2.0 - Modify prompt - Change library to stable version - Modify apiKey and related logic in build gradle - Refine Code --- app/build.gradle.kts | 4 ++-- .../java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1943e17..056131a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -14,8 +14,8 @@ android { applicationId = "levi.lin.gemini.android" minSdk = 30 targetSdk = 34 - versionCode = 8 - versionName = "0.1.1" + versionCode = 9 + versionName = "0.2.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt b/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt index f87da39..a01b6a9 100644 --- a/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt +++ b/app/src/main/java/levi/lin/gemini/android/viewmodel/GeminiViewModel.kt @@ -28,7 +28,7 @@ class GeminiViewModel( private val _selectedImageBitmaps = MutableStateFlow>(emptyList()) val selectedImageBitmaps: StateFlow> = _selectedImageBitmaps.asStateFlow() - private val _selectedImageCount = MutableStateFlow(0) + private val _selectedImageCount = MutableStateFlow(value = 0) val selectedImageCount: StateFlow = _selectedImageCount.asStateFlow() private val _generativeModelFlow = MutableSharedFlow() @@ -57,7 +57,7 @@ class GeminiViewModel( _uiState.value = GeminiUiState.Success(outputContent) } } catch (e: Exception) { - _uiState.value = GeminiUiState.Error(e.localizedMessage ?: "") + _uiState.value = GeminiUiState.Error(errorMessage = e.localizedMessage ?: "") } } }