-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist running ai tasks when switching conversations
Signed-off-by: Marcel Müller <[email protected]>
- Loading branch information
1 parent
ce53e6a
commit 26a016c
Showing
3 changed files
with
73 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// | ||
|
||
import Foundation | ||
|
||
public typealias RoomInternalIdString = String | ||
|
||
public class AiSummaryTask { | ||
public var taskIds = [Int]() | ||
public var outputs = [String]() | ||
} | ||
|
||
public class AiSummaryController { | ||
|
||
public static let shared = AiSummaryController() | ||
|
||
public var generateSummaryTasks = [RoomInternalIdString: AiSummaryTask]() | ||
|
||
public func addSummaryTaskId(forRoomInternalId internalId: String, withTaskId taskId: Int) { | ||
let task = generateSummaryTasks[internalId, default: AiSummaryTask()] | ||
|
||
task.taskIds.append(taskId) | ||
generateSummaryTasks[internalId] = task | ||
} | ||
|
||
public func markSummaryTaskAsDone(forRoomInternalId internalId: String, withTaskId taskId: Int, withOutput output: String) { | ||
guard let task = generateSummaryTasks[internalId] else { return } | ||
|
||
task.taskIds.removeAll(where: { $0 == taskId }) | ||
task.outputs.append(output) | ||
} | ||
|
||
public func finalizeSummaryTask(forRoomInternalId internalId: String) -> [String] { | ||
let result = generateSummaryTasks[internalId]?.outputs ?? [] | ||
generateSummaryTasks.removeValue(forKey: internalId) | ||
|
||
return result | ||
} | ||
|
||
public func getSummaryTaskIds(forRoomInternalId internalId: String) -> [Int] { | ||
return generateSummaryTasks[internalId]?.taskIds ?? [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters