Skip to content

Commit

Permalink
use SwiftyJSONLines to handle json lines fetched from batche result…
Browse files Browse the repository at this point in the history
…s api
  • Loading branch information
fumito-ito committed Oct 24, 2024
1 parent 3dc3cc2 commit 2353162
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 95 deletions.
86 changes: 0 additions & 86 deletions .swiftpm/configuration/Package.resolved

This file was deleted.

21 changes: 15 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,35 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-cmark.git",
"state" : {
"revision" : "3bc2f3e25df0cecc5dc269f7ccae65d0f386f06a",
"version" : "0.4.0"
"revision" : "3ccff77b2dc5b96b77db3da0d68d28068593fa53",
"version" : "0.5.0"
}
},
{
"identity" : "swift-markdown",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-markdown.git",
"state" : {
"revision" : "4aae40bf6fff5286e0e1672329d17824ce16e081",
"version" : "0.4.0"
"revision" : "8f79cb175981458a0a27e76cb42fee8e17b1a993",
"version" : "0.5.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25",
"version" : "600.0.0"
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
},
{
"identity" : "swiftyjsonlines",
"kind" : "remoteSourceControl",
"location" : "https://github.com/fumito-ito/SwiftyJSONLines.git",
"state" : {
"revision" : "ae30455420897b2c45621a88b3ae3f052a8b5f3d",
"version" : "0.0.2"
}
}
],
Expand Down
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ let package = Package(
targets: ["AnthropicSwiftSDK"]),
],
dependencies: [
.package(url: "https://github.com/fumito-ito/FunctionCalling", from: "0.4.0")
.package(url: "https://github.com/fumito-ito/FunctionCalling", from: "0.4.0"),
.package(url: "https://github.com/fumito-ito/SwiftyJSONLines.git", from: "0.0.2")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "AnthropicSwiftSDK",
dependencies: [
.product(name: "FunctionCalling", package: "FunctionCalling")
.product(name: "FunctionCalling", package: "FunctionCalling"),
.product(name: "SwiftyJSONLines", package: "SwiftyJSONLines")
]
),
.testTarget(
Expand Down
3 changes: 2 additions & 1 deletion Sources/AnthropicSwiftSDK/MessageBatches.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation
import FunctionCalling
import SwiftyJSONLines

public struct MessageBatches {
private let apiKey: String
Expand Down Expand Up @@ -113,7 +114,7 @@ public struct MessageBatches {
throw AnthropicAPIError(fromHttpStatusCode: httpResponse.statusCode)
}

return try anthropicJSONDecoder.decode([BatchResultResponse].self, from: data)
return try JSONLines(data: data).toObjects(with: anthropicJSONDecoder)
}

public func results(streamOf batchId: String) async throws -> AsyncThrowingStream<BatchResultResponse, Error> {
Expand Down

0 comments on commit 2353162

Please sign in to comment.