Skip to content

Commit 3f5f4f8

Browse files
committed
LLMOpenAI: refactor generation call to OpenAI API
See: apple/swift-openapi-runtime#115
1 parent b48e39f commit 3f5f4f8

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let package = Package(
3737
.package(url: "https://github.com/StanfordSpezi/SpeziChat", .upToNextMinor(from: "0.2.1")),
3838
.package(url: "https://github.com/StanfordSpezi/SpeziViews", from: "1.3.1"),
3939
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
40-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
40+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.6.0"),
4141
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0")
4242
],
4343
targets: [

Sources/SpeziLLMOpenAI/LLMOpenAISession+Generation.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ extension LLMOpenAISession {
3939
}
4040

4141
let chatStream = try response.ok.body.text_event_hyphen_stream
42-
.asDecodedServerSentEvents()
43-
.filter { $0.data != "[DONE]" }
44-
.asEncodedServerSentEvents()
45-
.asDecodedServerSentEventsWithJSONData(of:
46-
Components.Schemas.CreateChatCompletionStreamResponse.self)
42+
.asDecodedServerSentEventsWithJSONData(
43+
of: Components.Schemas.CreateChatCompletionStreamResponse.self,
44+
decoder: .init(),
45+
while: { incomingData in incomingData != ArraySlice<UInt8>(Data("[DONE]".utf8)) }
46+
)
4747

4848
for try await chatStreamResult in chatStream {
4949
guard let choices = chatStreamResult.data?.choices else {

0 commit comments

Comments
 (0)