-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from elimu-ai/4-chat-ui
feat: #4 Chat UI
- Loading branch information
Showing
30 changed files
with
791 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
app/src/androidTest/java/ai/elimu/soga/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
app/src/main/kotlin/com/google/ai/soga/GenerativeAiViewModelFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.