Skip to content

Commit 1eb0fc3

Browse files
authored
Merge pull request #137 from Taewan-P/fix/anthropic-api-update
Add new required types for Anthropic API
2 parents 20fb65a + 5592fdd commit 1eb0fc3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/dto/anthropic/response/Usage.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ data class Usage(
99
@SerialName("input_tokens")
1010
val inputTokens: Int,
1111

12+
@SerialName("cache_creation_input_tokens")
13+
val cacheCreationInputTokens: Int? = null,
14+
15+
@SerialName("cache_read_input_tokens")
16+
val cacheReadInputTokens: Int? = null,
17+
1218
@SerialName("output_tokens")
1319
val outputTokens: Int
1420
)

app/src/main/kotlin/dev/chungjungsoo/gptmobile/data/network/AnthropicAPIImpl.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,14 @@ class AnthropicAPIImpl @Inject constructor(
7171

7272
private suspend inline fun <reified T> FlowCollector<T>.streamEventsFrom(response: HttpResponse) {
7373
val channel: ByteReadChannel = response.body()
74+
val jsonInstance = Json { ignoreUnknownKeys = true }
75+
7476
try {
7577
while (currentCoroutineContext().isActive && !channel.isClosedForRead) {
7678
val line = channel.readUTF8Line() ?: continue
7779
val value: T = when {
7880
line.startsWith(STREAM_END_TOKEN) -> break
79-
line.startsWith(STREAM_PREFIX) -> Json.decodeFromString(line.removePrefix(STREAM_PREFIX))
81+
line.startsWith(STREAM_PREFIX) -> jsonInstance.decodeFromString(line.removePrefix(STREAM_PREFIX))
8082
else -> continue
8183
}
8284
emit(value)

0 commit comments

Comments
 (0)