From 7e85eb8b8891b6df3f0986f7ca6169accd30fdfc Mon Sep 17 00:00:00 2001 From: Ashraful Islam Date: Fri, 12 Apr 2024 14:46:29 -0500 Subject: [PATCH] adds a check before proceeding with generation (#51) --- Applications/LLMEval/ContentView.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Applications/LLMEval/ContentView.swift b/Applications/LLMEval/ContentView.swift index 0674131..efa375b 100644 --- a/Applications/LLMEval/ContentView.swift +++ b/Applications/LLMEval/ContentView.swift @@ -201,14 +201,20 @@ class LLMEvaluator { } func generate(prompt: String) async { - do { - let (model, tokenizer) = try await load() - - await MainActor.run { + let canGenerate = await MainActor.run { + if running { + return false + } else { running = true self.output = "" + return true } + } + guard canGenerate else { return } + + do { + let (model, tokenizer) = try await load() // augment the prompt as needed let prompt = modelConfiguration.prepare(prompt: prompt) let promptTokens = tokenizer.encode(text: prompt)