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 all 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
21 changes: 20 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,17 @@ 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 android.util.Log
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 @@ -52,11 +59,23 @@ import androidx.compose.ui.res.painterResource
internal fun ChatRoute(
chatViewModel: ChatViewModel = viewModel(factory = GenerativeViewModelFactory)
) {
Log.i("Mytag","ChatRoute")
val chatUiState by chatViewModel.uiState.collectAsState()
val listState = rememberLazyListState()
val coroutineScope = rememberCoroutineScope()


Scaffold(
topBar = {
// backgroundColor="transparent"
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 +227,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
@@ -1,5 +1,6 @@
package ai.elimu.soga.feature.chat

import android.util.Log
import androidx.compose.runtime.toMutableStateList

class ChatUiState(
Expand All @@ -18,6 +19,7 @@ class ChatUiState(
val newMessage = lastMessage.apply { isPending = false }
_messages.removeLast()
_messages.add(newMessage)
Log.i("Mytag","ChatUiState")
Copy link

Choose a reason for hiding this comment

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

The logging statement uses a generic tag "Mytag" and a static message, which might not provide sufficient context for debugging. Consider using a more descriptive tag and including dynamic information relevant to the operation or state, such as the message ID or type being replaced. Additionally, ensure that logging at this level is necessary and does not impact the application's performance or leak sensitive information.

- Log.i("Mytag","ChatUiState")
+ Log.i("ChatUiState", "Replacing last pending message with ID: ${newMessage.id}")

Note: Adjust the logging message as appropriate to include relevant dynamic information.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
Log.i("Mytag","ChatUiState")
Log.i("ChatUiState", "Replacing last pending message with ID: ${newMessage.id}")

}
}
}
10 changes: 10 additions & 0 deletions app/src/main/kotlin/ai/elimu/soga/feature/chat/ChatViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ai.elimu.soga.feature.chat

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.ai.client.generativeai.GenerativeModel
Expand All @@ -13,6 +14,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,12 +47,16 @@ class ChatViewModel(
)
)



viewModelScope.launch {
try {
val response = chat.sendMessage(userMessage)

_uiState.value.replaceLastPendingMessage()

Log.i("NumberGenerated","Number 2")

response.text?.let { modelResponse ->
_uiState.value.addMessage(
ChatMessage(
Expand All @@ -57,6 +65,8 @@ class ChatViewModel(
isPending = false
)
)
if (modelResponse.contains("\uD83C\uDF1F") || modelResponse.contains("Nya") || modelResponse.contains("Correct") || modelResponse.contains("that's right") || modelResponse.contains("fantastic")) { pointCounter += 0.1f
Log.i("Mytag","viewModelScope") }
}
} 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>
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ dependencyResolutionManagement {
}
}

rootProject.name = "Soga"
include(":app")
Loading