Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ jobs:
fail-fast: false
matrix:
include:
- macos: "15"
swift: "6.1"
xcode: "16.3"
traits: ""
- macos: "15"
swift: "6.1"
xcode: "16.3"
traits: "AsyncHTTPClient"
# Temporarily remove Swift 6.1 because mlx-swift-lm 3 uses Swift 6 mode and there's
# a strict concurrency error on a non-sendable CIContext.
# - macos: "15"
# swift: "6.1"
# xcode: "16.3"
# traits: ""
# - macos: "15"
# swift: "6.1"
# xcode: "16.3"
# traits: "AsyncHTTPClient"
- macos: "26"
swift: "6.2"
xcode: "26.0"
Expand Down
15 changes: 7 additions & 8 deletions Sources/AnyLanguageModel/Extensions/HTTPClient+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import Foundation
import NIOCore
import NIOHTTP1
import NIOFoundationCompat

extension HTTPClient {
func fetch<T: Decodable>(
Expand All @@ -32,21 +31,21 @@
}

if let body {
request.body = .bytes(ByteBuffer(data: body))
request.body = .bytes(ByteBuffer(bytes: body))
request.headers.add(name: "Content-Type", value: "application/json")
}

let response = try await self.execute(request, timeout: .seconds(180))

guard (200 ..< 300).contains(response.status.code) else {
let bodyData = try await Data(buffer: response.body.collect(upTo: 1024 * 1024))
let bodyData = try await Data(response.body.collect(upTo: 1024 * 1024).readableBytesView)
if let errorString = String(data: bodyData, encoding: .utf8) {
throw HTTPClientError.httpError(statusCode: Int(response.status.code), detail: errorString)
}
throw HTTPClientError.httpError(statusCode: Int(response.status.code), detail: "Invalid response")
}

let bodyData = try await Data(buffer: response.body.collect(upTo: 1024 * 1024))
let bodyData = try await Data(response.body.collect(upTo: 1024 * 1024).readableBytesView)

let decoder = JSONDecoder()
decoder.dateDecodingStrategy = dateDecodingStrategy
Expand Down Expand Up @@ -80,14 +79,14 @@
}

if let body {
request.body = .bytes(ByteBuffer(data: body))
request.body = .bytes(ByteBuffer(bytes: body))
request.headers.add(name: "Content-Type", value: "application/json")
}

let response = try await self.execute(request, timeout: .seconds(60))

guard (200 ..< 300).contains(response.status.code) else {
let bodyData = try await Data(buffer: response.body.collect(upTo: 1024 * 1024))
let bodyData = try await Data(response.body.collect(upTo: 1024 * 1024).readableBytesView)
if let errorString = String(data: bodyData, encoding: .utf8) {
throw HTTPClientError.httpError(
statusCode: Int(response.status.code),
Expand Down Expand Up @@ -149,14 +148,14 @@
}

if let body {
request.body = .bytes(ByteBuffer(data: body))
request.body = .bytes(ByteBuffer(bytes: body))
request.headers.add(name: "Content-Type", value: "application/json")
}

let response = try await self.execute(request, timeout: .seconds(60))

guard (200 ..< 300).contains(response.status.code) else {
let bodyData = try await Data(buffer: response.body.collect(upTo: 1024 * 1024))
let bodyData = try await Data(response.body.collect(upTo: 1024 * 1024).readableBytesView)
if let errorString = String(data: bodyData, encoding: .utf8) {
throw HTTPClientError.httpError(
statusCode: Int(response.status.code),
Expand Down