-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathCopilotModelManager.swift
More file actions
43 lines (35 loc) · 1.61 KB
/
CopilotModelManager.swift
File metadata and controls
43 lines (35 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import ConversationServiceProvider
import Foundation
public extension Notification.Name {
static let gitHubCopilotModelsDidChange = Notification
.Name("com.github.CopilotForXcode.CopilotModelsDidChange")
static let gitHubCopilotShouldSwitchFallbackModel = Notification
.Name("com.github.CopilotForXcode.CopilotShouldSwitchFallbackModel")
}
public class CopilotModelManager {
private static var availableLLMs: [CopilotModel] = []
private static var fallbackLLMs: [CopilotModel] = []
public static func updateLLMs(_ models: [CopilotModel]) {
let sortedModels = models.sorted(by: { $0.modelName.lowercased() < $1.modelName.lowercased() })
guard sortedModels != availableLLMs else { return }
availableLLMs = sortedModels
fallbackLLMs = models.filter({ $0.isChatFallback})
NotificationCenter.default.post(name: .gitHubCopilotModelsDidChange, object: nil)
}
public static func getAvailableLLMs() -> [CopilotModel] {
return availableLLMs
}
public static func hasLLMs() -> Bool {
return !availableLLMs.isEmpty
}
public static func getFallbackLLM(scope: PromptTemplateScope) -> CopilotModel? {
return fallbackLLMs.first(where: { $0.scopes.contains(scope) && $0.billing?.isPremium == false})
}
public static func switchToFallbackModel() {
NotificationCenter.default.post(name: .gitHubCopilotShouldSwitchFallbackModel, object: nil)
}
public static func clearLLMs() {
availableLLMs = []
NotificationCenter.default.post(name: .gitHubCopilotModelsDidChange, object: nil)
}
}