Skip to content

Commit

Permalink
LLMOpenAI: refactor generation call to OpenAI API
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhdk committed Dec 16, 2024
1 parent 6471784 commit 91b3f8d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let package = Package(
.package(url: "https://github.com/StanfordSpezi/SpeziChat", .upToNextMinor(from: "0.2.1")),
.package(url: "https://github.com/StanfordSpezi/SpeziViews", from: "1.3.1"),
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.6.0"),
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0")
],
targets: [
Expand Down
10 changes: 5 additions & 5 deletions Sources/SpeziLLMOpenAI/LLMOpenAISession+Generation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ extension LLMOpenAISession {
}

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

for try await chatStreamResult in chatStream {
guard let choices = chatStreamResult.data?.choices else {
Expand Down

0 comments on commit 91b3f8d

Please sign in to comment.