Skip to content

Commit

Permalink
Migrate from palm to gemini
Browse files Browse the repository at this point in the history
  • Loading branch information
mhss1 committed May 10, 2024
1 parent 07c8b7e commit 3a19d68
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 273 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
alt="Get it on GitHub"
height="80">](https://github.com/mhss1/AIStudyAssistant/releases/latest)

AI Study Assistant is an app designed to enhance your learning experience and boost academic performance. With a comprehensive set of AI-powered features, it serves as your personal tutor, lecture summarizer, writer, and question generator all powered by Google PaLM 2. Whether you need assistance with specific topics, summarizing lectures, crafting essays, or generating practice questions, AI Study Assistant has got you covered.
AI Study Assistant is an app designed to enhance your learning experience and boost academic performance. With a comprehensive set of AI-powered features, it serves as your personal tutor, lecture summarizer, writer, and question generator all powered by Google Gemini pro. Whether you need assistance with specific topics, summarizing lectures, crafting essays, or generating practice questions, AI Study Assistant has got you covered.

## Features:

Expand Down
43 changes: 18 additions & 25 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "com.mo.sh.studyassistant"
minSdk 26
targetSdk 34
versionCode 2
versionName "1.0.1"
versionCode 3
versionName "1.0.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -64,35 +64,34 @@ android {
}

dependencies {
def room_version = "2.5.2"
def nav_version = "2.7.3"
def lifecycle_version = "2.6.2"
def ktor_version = "2.0.0"
def room_version = "2.6.1"
def nav_version = "2.7.7"
def lifecycle_version = "2.7.0"

implementation 'androidx.core:core-ktx:1.12.0'
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.9.0')
implementation 'androidx.core:core-ktx:1.13.1'
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.9.20')
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation 'androidx.activity:activity-compose:1.7.2'
implementation platform('androidx.compose:compose-bom:2023.09.02')
implementation 'androidx.activity:activity-compose:1.9.0'
implementation platform('androidx.compose:compose-bom:2024.05.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
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:2022.10.00')
androidTestImplementation platform('androidx.compose:compose-bom:2024.05.00')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'

// Hilt
implementation "com.google.dagger:hilt-android:2.48"
ksp "com.google.dagger:hilt-compiler:2.48"
implementation "com.google.dagger:hilt-android:2.49"
ksp "com.google.dagger:hilt-compiler:2.49"

// Navigation
implementation "androidx.navigation:navigation-compose:$nav_version"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
implementation 'androidx.hilt:hilt-navigation-compose:1.2.0'

// Room
implementation "androidx.room:room-runtime:$room_version"
Expand Down Expand Up @@ -122,26 +121,20 @@ dependencies {
// Image cropper
implementation "com.vanniktech:android-image-cropper:4.5.0"

// Ktor
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-android:$ktor_version"
implementation "io.ktor:ktor-serialization-kotlinx-json:$ktor_version"
implementation "io.ktor:ktor-client-logging:$ktor_version"
implementation "ch.qos.logback:logback-classic:1.2.10"
implementation "io.ktor:ktor-client-content-negotiation:$ktor_version"
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0'

// Compose markdown
implementation 'com.github.jeziellago:compose-markdown:0.3.4'
implementation 'com.github.jeziellago:compose-markdown:0.5.0'

// DataStore
implementation "androidx.datastore:datastore-preferences:1.0.0"
implementation "androidx.datastore:datastore-preferences:1.1.1"

// Squircle shape
implementation "com.github.stoyan-vuchev:squircle-shape:1.0.3"

// Baseline profiler
implementation "androidx.profileinstaller:profileinstaller:1.3.1"

// Google generative ai
implementation("com.google.ai.client.generativeai:generativeai:0.5.0")
}

ksp {
Expand Down
29 changes: 2 additions & 27 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,8 @@
# hide the original source file name.
#-renamesourcefileattribute SourceFile


# Keep `Companion` object fields of serializable classes.
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
-if @kotlinx.serialization.Serializable class **
-keepclassmembers class <1> {
static <1>$Companion Companion;
}

# Keep `serializer()` on companion objects (both default and named) of serializable classes.
-if @kotlinx.serialization.Serializable class ** {
static **$* *;
}
-keepclassmembers class <2>$<3> {
kotlinx.serialization.KSerializer serializer(...);
}

# Keep `INSTANCE.serializer()` of serializable objects.
-if @kotlinx.serialization.Serializable class ** {
public static ** INSTANCE;
}
-keepclassmembers class <1> {
public static <1> INSTANCE;
kotlinx.serialization.KSerializer serializer(...);
}

# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault
# all in com.google.ai
-keep class com.google.ai.** { *; }

-dontwarn com.gemalto.jp2.JP2Decoder
-dontwarn groovy.lang.GroovyObject
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.mo.sh.studyassistant.data.network

import com.google.ai.client.generativeai.GenerativeModel
import com.google.ai.client.generativeai.type.BlockThreshold
import com.google.ai.client.generativeai.type.Content
import com.google.ai.client.generativeai.type.HarmCategory
import com.google.ai.client.generativeai.type.SafetySetting
import com.google.ai.client.generativeai.type.generationConfig


class GeminiApi {

private val safetySettings = listOf(
SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.ONLY_HIGH),
SafetySetting(HarmCategory.HATE_SPEECH, BlockThreshold.ONLY_HIGH),
SafetySetting(HarmCategory.DANGEROUS_CONTENT, BlockThreshold.ONLY_HIGH),
SafetySetting(HarmCategory.SEXUALLY_EXPLICIT, BlockThreshold.ONLY_HIGH),
)
private val temp = 0.4f
private val candidates = 1


suspend fun generateMessage(
history: List<Content>,
message: String,
key: String
): String? {
val generativeModel = GenerativeModel(
modelName = "gemini-1.0-pro-latest",
apiKey = key,
generationConfig = generationConfig {
temperature = temp
maxOutputTokens = 1024
candidateCount = candidates
},
safetySettings = safetySettings
)
return generativeModel.startChat(
history
).sendMessage(message).text
}

suspend fun generateText(
prompt: String,
key: String,
): String? {
val generativeModel = GenerativeModel(
modelName = "gemini-1.0-pro-latest",
apiKey = key,
generationConfig = generationConfig {
temperature = temp
maxOutputTokens = 2048
candidateCount = candidates
},
safetySettings = safetySettings
)
return generativeModel.generateContent(prompt).text
}

}

This file was deleted.

50 changes: 0 additions & 50 deletions app/src/main/java/com/mo/sh/studyassistant/data/network/PalmApi.kt

This file was deleted.

Loading

0 comments on commit 3a19d68

Please sign in to comment.