diff --git a/DesktopAI/ContentView.swift b/DesktopAI/ContentView.swift index a545aec..4eed053 100644 --- a/DesktopAI/ContentView.swift +++ b/DesktopAI/ContentView.swift @@ -47,7 +47,7 @@ struct ContentView: View { Section(header: Text(provider)) { ForEach(models, id: \.id) { model in Button(action: { - addItem(model: model.id) + addItem(model: model.id, provider: provider) }) { Text(model.id) } @@ -93,9 +93,9 @@ struct ContentView: View { } } - private func addItem(model: String) { + private func addItem(model: String, provider: String) { withAnimation { - let newItem = Item(timestamp: Date(), model: model) + let newItem = Item(timestamp: Date(), model: model, provider: provider) modelContext.insert(newItem) } } diff --git a/DesktopAI/DisplayChats.swift b/DesktopAI/DisplayChats.swift index 9efa3ab..d69cd65 100644 --- a/DesktopAI/DisplayChats.swift +++ b/DesktopAI/DisplayChats.swift @@ -47,7 +47,24 @@ struct DisplayChats: View { selectedItem.chatHistory.append(newMessage) userMessage = "" - let provider = GroqProvider() + let provider: BaseProvider? + + switch selectedItem.provider { + case "Groq": + provider = GroqProvider() + case "OpenAI": + provider = OpenAIProvider() + case "CloudflareAI": + provider = CloudflareAIProvider() + + default: + return + } + + guard let provider = provider else { + return + } + provider.userSentChatMessage(item: selectedItem) }) .textFieldStyle(RoundedBorderTextFieldStyle()) diff --git a/DesktopAI/Item.swift b/DesktopAI/Item.swift index e33479b..43cba2d 100644 --- a/DesktopAI/Item.swift +++ b/DesktopAI/Item.swift @@ -13,12 +13,14 @@ final class Item { var id: UUID var timestamp: Date var model: String + var provider: String @Relationship(deleteRule: .cascade) var chatHistory: [ChatMessage] = [] - init(timestamp: Date, model: String) { + init(timestamp: Date, model: String, provider: String) { self.id = UUID() self.timestamp = timestamp self.model = model + self.provider = provider } }