Implement optional discussion mode
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import Foundation
|
||||
|
||||
public final class SongProjectDiscussionDirector: Sendable {
|
||||
private let aiService: any AIService
|
||||
|
||||
public init(aiService: any AIService) {
|
||||
self.aiService = aiService
|
||||
}
|
||||
|
||||
public func discuss(
|
||||
project: SongProject,
|
||||
userMessage: String,
|
||||
conversation: [AIConversationMessage] = [],
|
||||
localeIdentifier: String? = nil
|
||||
) async throws -> SongProjectDiscussionResult {
|
||||
guard project.conversationMode == .discuss else {
|
||||
throw SongProjectDiscussionDirectorError.discussionModeNotEnabled
|
||||
}
|
||||
|
||||
let trimmedMessage = userMessage.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
guard !trimmedMessage.isEmpty else {
|
||||
throw SongProjectDiscussionDirectorError.emptyUserMessage
|
||||
}
|
||||
|
||||
let result = try await aiService.discussSongProject(
|
||||
from: SongProjectDiscussionRequest(
|
||||
context: AIRequestContext(
|
||||
userInstruction: trimmedMessage,
|
||||
conversation: conversation,
|
||||
localeIdentifier: localeIdentifier
|
||||
),
|
||||
project: project
|
||||
)
|
||||
)
|
||||
|
||||
return SongProjectDiscussionResult(
|
||||
questions: result.questions
|
||||
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
|
||||
.filter { !$0.isEmpty },
|
||||
notes: result.notes
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public enum SongProjectDiscussionDirectorError: Error, Equatable, Sendable {
|
||||
case discussionModeNotEnabled
|
||||
case emptyUserMessage
|
||||
}
|
||||
Reference in New Issue
Block a user