Skip to content

Commit

Permalink
Fixed marking of response generation completed control flow in LlmInf…
Browse files Browse the repository at this point in the history
…erence+Session.
  • Loading branch information
priankakariatyml committed Aug 26, 2024
1 parent 3d650fd commit a4c6a6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ final class LlmSessionRunner {
func predictAsync(
progress: @escaping (_ partialResult: [String]?, _ error: Error?) -> Void,
completion: @escaping (() -> Void)
) throws {
) {
let callbackInfo = CallbackInfo(progress: progress, completion: completion)
let callbackContext = UnsafeMutableRawPointer(Unmanaged.passRetained(callbackInfo).toOpaque())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ extension LlmInference {
/// TODO: If simultaneous response generations on multiple sessions or the same session
/// are allowed to happen it leads to a crash. Investigate if this can be handled by C++.
try llmInference.shouldContinueWithResponseGeneration()


defer {
llmInference.markResponseGenerationCompleted()
}

let tokens = try llmSessionRunner.predict()

llmInference.markResponseGenerationCompleted()

guard let humanReadableLlmResponse = Session.humanReadableString(llmResponses: tokens)
else {
throw GenAiInferenceError.invalidResponse
Expand Down Expand Up @@ -159,7 +161,7 @@ extension LlmInference {
/// Used to make a decision about whitespace stripping.
var receivedFirstToken = true

try llmSessionRunner.predictAsync(
llmSessionRunner.predictAsync(
progress: { partialResponseStrings, error in
guard let responseStrings = partialResponseStrings,
let humanReadableLlmResponse = Session.humanReadableString(
Expand Down

0 comments on commit a4c6a6a

Please sign in to comment.