Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
prapooskur committed Jan 21, 2024
1 parent 6652630 commit 11ab818
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions android/app/src/main/java/com/pras/slugcourses/ChatScreen.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,51 @@
package com.pras.slugcourses

import android.util.Log
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.engine.cio.CIO
import io.ktor.client.request.prepareGet
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.core.isEmpty
import io.ktor.utils.io.core.readBytes

//todo pls fix
private const val CHAT_URL = "http://localhost:8000/?userinput="
private const val TAG = "ChatScreen"
@Composable
fun ChatScreen(navController: NavController) {
Log.d(TAG, "ChatScreen")
//todo pls fix
//queryChat("hello")
Row(Modifier.padding(16.dp), verticalAlignment = Alignment.Bottom, horizontalArrangement = Arrangement.Center) {
//todo pls fix

}
}

suspend fun queryChat(query: String) {
//todo pls fix
val client = HttpClient(CIO)

client.prepareGet(CHAT_URL + query) .execute { httpResponse ->
val channel: ByteReadChannel = httpResponse.body()
var response: String = ""
while (!channel.isClosedForRead) {
val packet = channel.readRemaining(DEFAULT_BUFFER_SIZE.toLong())
while (!packet.isEmpty) {
val bytes = packet.readBytes()
response+=String(bytes)
Log.d(TAG, packet.readBytes().toString())
}
}
Log.d(TAG, response)
}
}

0 comments on commit 11ab818

Please sign in to comment.