Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add counter, and git make my day and i delete all my work) #16

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import ai.elimu.soga.GenerativeViewModelFactory
import ai.elimu.soga.R
import ai.elimu.soga.ui.theme.Gold80
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.StrokeCap
import kotlinx.coroutines.launch
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
Expand All @@ -57,6 +63,15 @@ internal fun ChatRoute(
val coroutineScope = rememberCoroutineScope()

Scaffold(
topBar = {
LinearProgressIndicator(
progress = chatViewModel.pointCounter,
modifier = Modifier.height(30.dp).fillMaxWidth().padding(10.dp,0.dp),
color = Gold80,
trackColor = Color.Black,
strokeCap = StrokeCap.Round,
)
},
bottomBar = {
MessageInput(
onSendMessage = { inputText ->
Expand Down Expand Up @@ -208,7 +223,7 @@ fun MessageInput(
.fillMaxWidth()
.weight(0.15f)
) {
Icon(
Icon(
Icons.Default.Send,
contentDescription = stringResource(R.string.action_send),
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import kotlinx.coroutines.launch
class ChatViewModel(
generativeModel: GenerativeModel
) : ViewModel() {

var pointCounter = 0.0f;

private val chat = generativeModel.startChat(
history = listOf(
content(role = "user") { text("You'll act as a friendly tutor who helps 6-year-old children learn basic math. Use emojis when you create word problems. Your name is Nya.") },
Expand Down Expand Up @@ -43,6 +46,8 @@ class ChatViewModel(
)
)



viewModelScope.launch {
try {
val response = chat.sendMessage(userMessage)
Expand All @@ -57,6 +62,7 @@ class ChatViewModel(
isPending = false
)
)
if (modelResponse.contains("\uD83C\uDF1F") || modelResponse.contains("correct") || modelResponse.contains("Correct")) { pointCounter += 0.1f }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (modelResponse.contains("\uD83C\uDF1F") || modelResponse.contains("correct") || modelResponse.contains("Correct")) { pointCounter += 0.1f }
if (modelResponse.contains("\uD83C\uDF1F") || modelResponse.toLowerCase().contains("that's correct") || modelResponse.toLowerCase().contains("correct!") || modelResponse.toLowerCase().contains("fantastic!") || modelResponse.toLowerCase().contains("that's right")) { pointCounter += 0.1f }

}
} catch (e: Exception) {
_uiState.value.replaceLastPendingMessage()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/kotlin/ai/elimu/soga/ui/theme/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ val Pink80 = Color(0xFFEFB8C8)
val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)

val Gold80 = Color(0xFFFFC94A)
3 changes: 3 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="gold">#FFFFC94A</color>


</resources>
Loading