Skip to content

Commit

Permalink
Remove GroqProvider hardcode
Browse files Browse the repository at this point in the history
  • Loading branch information
imkylecat committed May 14, 2024
1 parent 609e3ae commit 006b49c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 3 additions & 3 deletions DesktopAI/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
19 changes: 18 additions & 1 deletion DesktopAI/DisplayChats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion DesktopAI/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 006b49c

Please sign in to comment.