From e3a0cd31016ae392ae5bbf7ec23c1952a12e4de6 Mon Sep 17 00:00:00 2001 From: eastriver Date: Sat, 27 Jan 2024 09:56:48 +0900 Subject: [PATCH] add func getCompletion(from input: borrowing String) async -> String --- Sources/LLM/LLM.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/LLM/LLM.swift b/Sources/LLM/LLM.swift index 8406a59..d8ac6b5 100644 --- a/Sources/LLM/LLM.swift +++ b/Sources/LLM/LLM.swift @@ -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) async -> String) async { guard isAvailable else { return } isAvailable = false