Skip to content

Commit

Permalink
add func getCompletion(from input: borrowing String) async -> String
Browse files Browse the repository at this point in the history
  • Loading branch information
eastriverlee committed Jan 27, 2024
1 parent 0ead3ed commit e3a0cd3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/LLM/LLM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@ open class LLM: ObservableObject {
private var input: String = ""
private var isAvailable = true

public func getCompletion(from input: borrowing String) async -> String {
guard isAvailable else { fatalError("LLM is being used") }
isAvailable = false
let response = getResponse(from: input)
var output = ""
for await responseDelta in response {
output += responseDelta
}
isAvailable = true
return output
}

public func respond(to input: String, with makeOutputFrom: @escaping (AsyncStream<String>) async -> String) async {
guard isAvailable else { return }
isAvailable = false
Expand Down

0 comments on commit e3a0cd3

Please sign in to comment.