Skip to content

Commit

Permalink
Ignore unknown keys for future api updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Taewan-P committed Dec 18, 2024
1 parent f0cbeed commit 5592fdd
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ class AnthropicAPIImpl @Inject constructor(

private suspend inline fun <reified T> FlowCollector<T>.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)
Expand Down

0 comments on commit 5592fdd

Please sign in to comment.