Skip to content

Commit

Permalink
Add passing test for creating json input
Browse files Browse the repository at this point in the history
  • Loading branch information
kateliu20 committed Sep 18, 2024
1 parent 9cbda30 commit 9f9d447
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ChatPresenter : Presenter<ChatScreen.State> {
println("ChatPresenter: Fetching a quote")
val response = chatBotActionService.executeCommand(event.message)
println("ChatPresenter: Received response: $newMessage")
messages = messages + Message(role = user, response)
messages = messages + Message(role = bot, response)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ private fun ConversationField(modifier: Modifier = Modifier, onSendMessage: (Str

@Composable
private fun ChatBubble(message: Message, modifier: Modifier = Modifier) {
val user = "user"
val isMe = message.role == user

val isMe = message.role == "user"
Box(
Modifier.wrapContentWidth()
.padding(8.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ import com.google.gson.Gson
import org.junit.Test

class ChatBotActionServiceTest {
@Test
fun `say 1+1 equals 2`() {
val result = 1 + 1
val actual = 2
assertThat(actual).isEqualTo(result)
}

@Test
fun `test creating the Json input`() {
val question = "What's the capital of Canada"
val question = "Why is the sky blue?"

val result = createJsonInput(question)

Expand All @@ -39,27 +32,30 @@ class ChatBotActionServiceTest {
"messages": [
{
"role": "user",
"content": "What's the capital of Canada"
"content": "Why is the sky blue?"
}
],
"source": "curl",
"max_tokens": 2048
"max_tokens": 512
}
"""
.trimIndent()

println("expected is ${expectedJson}")
println("actual is ${result}")
val trimmedExpected = expectedJson.replace(Regex("\\s"), "")
val trimmedResult = result.replace(Regex("\\s"), "")
println("expected is ${trimmedExpected}")
println("actual is ${trimmedResult}")

assertThat(result).isEqualTo(expectedJson)
assertThat(trimmedResult).isEqualTo(trimmedExpected)
}

private fun createJsonInput(question: String): String {
val user = "user"
val gsonInput = Gson()
val content =
Content(messages = listOf(Message(role = user, question)), source = "curl", max_tokens = 2048)
Content(messages = listOf(Message(role = user, question)), source = "curl", max_tokens = 512)

val jsonContent = gsonInput.toJson(content)
val jsonContent = gsonInput.toJson(content).toString()
return jsonContent
}

Expand Down

0 comments on commit 9f9d447

Please sign in to comment.