diff --git a/app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/dto/anthropic/response/Usage.kt b/app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/dto/anthropic/response/Usage.kt index babd48a..4a3c3e4 100644 --- a/app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/dto/anthropic/response/Usage.kt +++ b/app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/dto/anthropic/response/Usage.kt @@ -9,6 +9,12 @@ data class Usage( @SerialName("input_tokens") val inputTokens: Int, + @SerialName("cache_creation_input_tokens") + val cacheCreationInputTokens: Int? = null, + + @SerialName("cache_read_input_tokens") + val cacheReadInputTokens: Int? = null, + @SerialName("output_tokens") val outputTokens: Int ) diff --git a/app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/network/AnthropicAPIImpl.kt b/app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/network/AnthropicAPIImpl.kt index a0e1488..1eedfc3 100644 --- a/app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/network/AnthropicAPIImpl.kt +++ b/app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/network/AnthropicAPIImpl.kt @@ -71,12 +71,14 @@ class AnthropicAPIImpl @Inject constructor( private suspend inline fun FlowCollector.streamEventsFrom(response: HttpResponse) { val channel: ByteReadChannel = response.body() + val jsonInstance = Json { ignoreUnknownKeys = true } + try { while (currentCoroutineContext().isActive && !channel.isClosedForRead) { val line = channel.readUTF8Line() ?: continue val value: T = when { line.startsWith(STREAM_END_TOKEN) -> break - line.startsWith(STREAM_PREFIX) -> Json.decodeFromString(line.removePrefix(STREAM_PREFIX)) + line.startsWith(STREAM_PREFIX) -> jsonInstance.decodeFromString(line.removePrefix(STREAM_PREFIX)) else -> continue } emit(value)