Skip to content

Commit

Permalink
Remove gemini sdk and fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
Taewan-P committed Mar 1, 2025
1 parent 31ce76a commit 5073271
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 59 deletions.
3 changes: 0 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ dependencies {
implementation(libs.androidx.lifecycle.runtime.compose.android)
ksp(libs.hilt.compiler)

// Gemini SDK
implementation(libs.gemini)

// Ktor
implementation(libs.ktor.content.negotiation)
implementation(libs.ktor.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface ChatRepository {

suspend fun completeOpenAIChat(question: Message, history: List<Message>): Flow<ApiState>
suspend fun completeAnthropicChat(question: Message, history: List<Message>): Flow<ApiState>
suspend fun completeGoogleChat(question: Message, history: List<Message>): Flow<ApiState>
suspend fun completeGroqChat(question: Message, history: List<Message>): Flow<ApiState>
suspend fun completeOllamaChat(question: Message, history: List<Message>): Flow<ApiState>
suspend fun fetchChatList(): List<ChatRoom>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ import com.aallam.openai.api.chat.ChatRole
import com.aallam.openai.api.model.ModelId
import com.aallam.openai.client.OpenAI
import com.aallam.openai.client.OpenAIHost
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.GenerateContentResponse
import com.google.ai.client.generativeai.type.HarmCategory
import com.google.ai.client.generativeai.type.SafetySetting
import com.google.ai.client.generativeai.type.content
import com.google.ai.client.generativeai.type.generationConfig
import dev.chungjungsoo.gptmobile.data.ModelConstants
import dev.chungjungsoo.gptmobile.data.database.dao.ChatRoomDao
import dev.chungjungsoo.gptmobile.data.database.dao.ChatRoomV2Dao
Expand Down Expand Up @@ -51,7 +43,6 @@ class ChatRepositoryImpl @Inject constructor(
) : ChatRepository {

private lateinit var openAI: OpenAI
private lateinit var google: GenerativeModel
private lateinit var ollama: OpenAI
private lateinit var groq: OpenAI

Expand Down Expand Up @@ -108,34 +99,6 @@ class ChatRepositoryImpl @Inject constructor(
.onCompletion { emit(ApiState.Done) }
}

override suspend fun completeGoogleChat(question: Message, history: List<Message>): Flow<ApiState> {
val platform = checkNotNull(settingRepository.fetchPlatforms().firstOrNull { it.name == ApiType.GOOGLE })
val config = generationConfig {
temperature = platform.temperature
topP = platform.topP
}
val prompt = platform.systemPrompt ?: ModelConstants.DEFAULT_PROMPT
google = GenerativeModel(
modelName = platform.model ?: "",
apiKey = platform.token ?: "",
systemInstruction = if (prompt.isEmpty()) null else content { text(prompt) },
generationConfig = config,
safetySettings = listOf(
SafetySetting(HarmCategory.DANGEROUS_CONTENT, BlockThreshold.ONLY_HIGH),
SafetySetting(HarmCategory.SEXUALLY_EXPLICIT, BlockThreshold.NONE)
)
)

val inputContent = messageToGoogleMessage(history)
val chat = google.startChat(history = inputContent)

return chat.sendMessageStream(question.content)
.map<GenerateContentResponse, ApiState> { response -> ApiState.Success(response.text ?: "") }
.catch { throwable -> emit(ApiState.Error(throwable.message ?: "Unknown error")) }
.onStart { emit(ApiState.Loading) }
.onCompletion { emit(ApiState.Done) }
}

override suspend fun completeGroqChat(question: Message, history: List<Message>): Flow<ApiState> {
val platform = checkNotNull(settingRepository.fetchPlatforms().firstOrNull { it.name == ApiType.GROQ })
groq = OpenAI(platform.token ?: "", host = OpenAIHost(baseUrl = platform.apiUrl))
Expand Down Expand Up @@ -332,20 +295,4 @@ class ChatRepositoryImpl @Inject constructor(

return result
}

private fun messageToGoogleMessage(messages: List<Message>): List<Content> {
val result = mutableListOf<Content>()

messages.forEach { message ->
when (message.platformType) {
null -> result.add(content(role = "user") { text(message.content) })

ApiType.GOOGLE -> result.add(content(role = "model") { text(message.content) })

else -> {}
}
}

return result
}
}
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ lifecycleRuntime = "2.8.7"
activityCompose = "1.10.1"
composeBom = "2025.02.00"
datastore = "1.1.3"
gemini = "0.9.0"
hilt = "2.55"
ksp = "2.0.21-1.0.28" # Also change with Kotlin version
ktor = "3.0.3"
Expand Down Expand Up @@ -43,7 +42,6 @@ androidx-material3 = { group = "androidx.compose.material3", name = "material3"
auto-license-core = { group = "com.mikepenz", name = "aboutlibraries-core", version.ref = "autoLicense" }
auto-license-ui = { group = "com.mikepenz", name = "aboutlibraries-compose-m3", version.ref = "autoLicense" }
compose-markdown = { group = "com.github.jeziellago", name = "compose-markdown", version.ref = "markdown" }
gemini = { group = "com.google.ai.client.generativeai", name = "generativeai", version.ref = "gemini"}
hilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
hilt-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }
hilt-navigation = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "androidxHilt" }
Expand Down

0 comments on commit 5073271

Please sign in to comment.