Skip to content

Commit

Permalink
Updated EventSource to version 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Recouse committed Feb 3, 2024
1 parent 2aae8d9 commit 175426e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
22 changes: 2 additions & 20 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Recouse/EventSource.git",
"state" : {
"revision" : "8799dad0908a1f36492fb63fb7e3e7d913bdda4d",
"version" : "0.0.6"
}
},
{
"identity" : "swift-async-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-async-algorithms.git",
"state" : {
"revision" : "9cfed92b026c524674ed869a4ff2dcfdeedf8a2a",
"version" : "0.1.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version" : "1.0.4"
"revision" : "ffaa978620b19c891d107941c1b36d18836e8ecb",
"version" : "0.0.7"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/Recouse/EventSource.git", from: "0.0.6")
.package(url: "https://github.com/Recouse/EventSource.git", from: "0.0.7")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
9 changes: 5 additions & 4 deletions Sources/OpenAI/Request/Handler/BaseRequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import os.log

public struct BaseRequestHandler: RequestHandler {
let urlSession: URLSession
let eventSource: EventSource

let decoder: JSONDecoder = .openAIDecoder

init(urlSession: URLSession = .shared) {
init(urlSession: URLSession = .shared, eventSource: EventSource = EventSource()) {
self.urlSession = urlSession
self.eventSource = eventSource
}

public func perform<T>(for model: T.Type, with request: Request) async throws -> T where T: Decodable {
Expand Down Expand Up @@ -43,10 +45,9 @@ public struct BaseRequestHandler: RequestHandler {

return AsyncThrowingStream { continuation in
Task {
let eventSource = EventSource(request: urlRequest, maxRetryCount: 1)
eventSource.connect()
let dataTask = eventSource.dataTask(for: urlRequest)

for await event in eventSource.events {
for await event in dataTask.events() {
switch event {
case .open:
continue
Expand Down

0 comments on commit 175426e

Please sign in to comment.